Here you can find the source of removeDuplicates(List list)
public static void removeDuplicates(List list)
//package com.java2s; import java.util.Collection; import java.util.Collections; import java.util.HashSet; import java.util.Iterator; import java.util.List; import java.util.Set; public class Main { public static void removeDuplicates(List list) { if ((list != null) && !list.isEmpty()) { Set set = new HashSet(list.size()); for (Iterator iter = list.iterator(); iter.hasNext();) { Object element = iter.next(); if (set.contains(element)) { iter.remove();//from w w w . j a v a 2 s . co m } else { set.add(element); } } } } /** * Returns 0 if the specified collection is null or the collection size * if not null. * * @param c the collection to size * @return the size of the collection */ public static int size(Collection c) { return (c == null) ? 0 : c.size(); } /** * Returns an iterator on a collection even null. * @param collection Collection * @return Iterator */ public static Iterator iterator(Collection collection) { if (collection == null) { return Collections.EMPTY_LIST.iterator(); } else { return collection.iterator(); } } }