import java.util.List;
import java.util.Set;
import java.util.ArrayList;
import java.util.HashSet;
public class list2Set{
public static void main(String args[]) {
try{
// Creating one sample list
List sampleList=new ArrayList();
// Adding some element into list
sampleList.add("One");
sampleList.add("Two");
sampleList.add("Three");
sampleList.add("One");
// Converting list in set. During this conversion all the duplicate elements are removed.
Set mySet=new HashSet(sampleList);
System.out.println(mySet);
}
catch(Exception e){
e.printStackTrace();
}
}
}
import java.util.Set;
import java.util.ArrayList;
import java.util.HashSet;
public class list2Set{
public static void main(String args[]) {
try{
// Creating one sample list
List sampleList=new ArrayList();
// Adding some element into list
sampleList.add("One");
sampleList.add("Two");
sampleList.add("Three");
sampleList.add("One");
// Converting list in set. During this conversion all the duplicate elements are removed.
Set mySet=new HashSet(sampleList);
System.out.println(mySet);
}
catch(Exception e){
e.printStackTrace();
}
}
}
Comments