Remove duplicates from an arraylist:
===========================
package selenium.basics;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.Iterator;
public class IteratorDemo {
public static void main(String[] args) {
ArrayList<String> arrayList = new ArrayList<String>();
arrayList.add("10");
arrayList.add("20");
arrayList.add("30");
arrayList.add("40");
arrayList.add("10");
arrayList.add("10");
arrayList.add("10");
arrayList.add("30");
arrayList.add("30");
System.out.println(arrayList);
HashSet hashSet = new HashSet(arrayList);
System.out.println(hashSet);
}
}
===========================
package selenium.basics;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.Iterator;
public class IteratorDemo {
public static void main(String[] args) {
ArrayList<String> arrayList = new ArrayList<String>();
arrayList.add("10");
arrayList.add("20");
arrayList.add("30");
arrayList.add("40");
arrayList.add("10");
arrayList.add("10");
arrayList.add("10");
arrayList.add("30");
arrayList.add("30");
System.out.println(arrayList);
HashSet hashSet = new HashSet(arrayList);
System.out.println(hashSet);
}
}
No comments:
Post a Comment