Java tutorial
//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(); 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<T1>(); for (Integer idx : indices) sublst.add(lst.get(idx)); return sublst; } }