Java List Create createUniqueProducts(List list1, List list2)

Here you can find the source of createUniqueProducts(List list1, List list2)

Description

Appends the newly fetched recommendation resources (that are not already contained) to the end of the list

License

Open Source License

Parameter

Parameter Description
existingRecommendations existing recommendations that will get the appended data
newlyFetchedRecommendations recommendations to be appended (if not already present)

Declaration

public static List<String> createUniqueProducts(List<String> list1,
        List<String> list2) 

Method Source Code

//package com.java2s;
//License from project: Open Source License 

import java.util.ArrayList;

import java.util.List;

public class Main {
    /**/*from w w  w.ja  va 2s .  c  o m*/
     * Appends the newly fetched recommendation resources (that are not already contained) to the end of the list
     * @param existingRecommendations existing recommendations that will get the appended data
     * @param newlyFetchedRecommendations recommendations to be appended (if not already present)
     */
    public static List<String> createUniqueProducts(List<String> list1,
            List<String> list2) {
        List<String> uniqueList = new ArrayList<String>();

        if (list1 != null) {
            for (String recommendedProduct : list1) {
                if (!uniqueList.contains(recommendedProduct)) {
                    uniqueList.add(recommendedProduct);
                }
            }
        }

        if (list2 != null) {
            for (String recommendedProduct : list2) {
                if (!uniqueList.contains(recommendedProduct)) {
                    uniqueList.add(recommendedProduct);
                }
            }
        }

        return uniqueList;
    }
}

Related

  1. createTable(List datas, String[] headers, int numColumns, int cellPadding, int border)
  2. createTagList(List tags, String separator)
  3. createTarget(List labels)
  4. createTargetSorted(List labels, Comparator comp)
  5. createTuple(List> tuples, List entries, List> lists)
  6. createUnmodifiableList(Collection coll)
  7. createUpdateMeasurementItemList(final String itemList, final String updateItem)
  8. createValues(int barCount, String valueDigits, int distributionType, List valueCounts)
  9. createWhereInClause(String field, List values, boolean isString)