Here you can find the source of removeDuplicates(List
public static <V> void removeDuplicates(List<V> lst)
//package com.java2s; import java.util.*; public class Main { public static <V> void removeDuplicates(List<V> lst) { for (ListIterator<V> it = lst.listIterator(); it.hasNext();) { int idx = it.nextIndex(); V elem = it.next();//from w w w.j ava2 s .co m if (idx < lst.size() - 1 && lst.subList(idx + 1, lst.size() - 1).contains(elem)) it.remove(); } } /** * Create a sub list with just these indices */ public static <T1> List<T1> subList(List<T1> lst, Collection<Integer> indices) { List<T1> sublst = new ArrayList<>(); for (Integer idx : indices) sublst.add(lst.get(idx)); return sublst; } }