Remove duplicate items from an ArrayList
>> Monday, May 23, 2011
import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
public class Main {
public static void main(String[] argv) {
List arrayList1 = new ArrayList ();
arrayList1.add("A");
arrayList1.add("A");
arrayList1.add("B");
arrayList1.add("B");
arrayList1.add("B");
arrayList1.add("C");
HashSet hashSet = new HashSet (arrayList1);
List arrayList2 = new ArrayList (hashSet);
for (Object item : arrayList2)
System.out.println(item);
}
}
0 comments:
Post a Comment