java4all@1986 java. Powered by Blogger.

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

FaceBook Login

HTML/JAVASCRIPT

HTML/JAVASCRIPT

HTML/JAVASCRIPT

HTML/JAVASCRIPT

Total Pageviews

STATCOUNTER

  © Blogger template Simple n' Sweet by Ourblogtemplates.com 2009

Back to TOP