Here you can find the source of combineList(List l1, List l2)
Parameter | Description |
---|---|
l1 | a parameter |
l2 | a parameter |
public static List combineList(List l1, List l2)
//package com.java2s; import java.util.*; public class Main { /**/* ww w . j a v a2 s . c o m*/ * Combine two lists (l1 -> l2) and return a new list, compare the item using List.contains(), so implement equals() * @param l1 * @param l2 * @return Combined list */ public static List combineList(List l1, List l2) { List resultList = new ArrayList(); if (l1 != null && l2 != null) { resultList.addAll(l1); for (int i = 0; i < l2.size(); i++) { Object o = l2.get(i); if (!resultList.contains(o)) { resultList.add(o); } } } else if (l1 != null && l2 == null) { resultList.addAll(l1); } else if (l1 == null && l2 != null) { resultList.addAll(l2); } return resultList; } }