Hiii frnds, this is a nice question in interview forum, so let's see how to remove duplicate objects from List / ArrayList
ArrayListExample.java
ArrayListExample.java
package java8s;
import java.util.*;
public class
ArrayListExample {
public static void main(String[] args) {
ArrayList
al=new ArrayList();
al.add("first");
al.add("second");
al.add("third");
al.add("first");
al.add("first");
ArrayList
al1=new ArrayList(new LinkedHashSet(al));
Iterator
it=al1.iterator();
while(it.hasNext())
{
System.out.println(it.next());
}
}
}
Output
first
second
third
No comments:
Post a Comment