Here you can find the source of addUnique(List
public static <T> List<T> addUnique(List<T> aList, T anObj)
//package com.java2s; import java.util.*; public class Main { /**/* www . j av a 2 s . c o m*/ * Adds an object to the given list if object is absent (creates list if missing). */ public static <T> List<T> addUnique(List<T> aList, T anObj) { return contains(aList, anObj) ? aList : add(aList, anObj); } /** * 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; } }