Here you can find the source of addAllUnique(List
public static <T> List<T> addAllUnique(List<T> aList, List<T> theObjects)
//package com.java2s; import java.util.*; public class Main { /**//from w ww .j ava2 s . co m * Adds all object from second list to first list (creates first list if missing). */ public static <T> List<T> addAllUnique(List<T> aList, List<T> theObjects) { // If list is null, create it if (aList == null) aList = new ArrayList(); // Add objects unique for (T object : theObjects) if (!aList.contains(object)) aList.add(object); // Return list return aList; } /** * Adds all object from second list to first list (creates first list if missing). */ public static <T> List<T> addAllUnique(List<T> aList, T... theObjects) { return addAllUnique(aList, aList != null ? aList.size() : 0, theObjects); } /** * Adds all object from second list to first list (creates first list if missing). */ public static <T> List<T> addAllUnique(List<T> aList, int anIndex, T... theObjects) { // If list is null, create it if (aList == null) aList = new ArrayList(); // Add objects unique for (int i = 0; i < theObjects.length; i++) { T object = theObjects[i]; if (!aList.contains(object)) aList.add(anIndex++, object); } // Return list return aList; } /** * Returns whether list contains given object (accepts null list). */ public static boolean contains(List aList, Object anObj) { return aList != null && aList.contains(anObj); } /** * Adds an object to the given list and returns list (creates list if missing). */ public static <T> List<T> add(List<T> aList, T anObj) { // If list is null, create list if (aList == null) aList = new Vector(); // Add object aList.add(anObj); // Return list return aList; } /** * Returns the size of a list (accepts null list). */ public static int size(List aList) { return aList == null ? 0 : aList.size(); } }