By Using HashSet implementation the order of the input may differ.
package collections;
import java.util.HashSet;
import java.util.Set;
public class HashSetCollection {
public static void main(String[] args) {
Set<String> hs=new HashSet<String>();
hs.add("hi");
hs.add("i");
hs.add("am");
hs.add("Abhishek");
hs.add("Awasthi");
hs.add("Abhishek Awasthi");
hs.add("hi");
hs.add("i");
hs.add("am");
System.out.println("Size: "+hs.size());
System.out.println("Distinct Words : "+hs);
}
}
package collections;
import java.util.HashSet;
import java.util.Set;
public class HashSetCollection {
public static void main(String[] args) {
Set<String> hs=new HashSet<String>();
hs.add("hi");
hs.add("i");
hs.add("am");
hs.add("Abhishek");
hs.add("Awasthi");
hs.add("Abhishek Awasthi");
hs.add("hi");
hs.add("i");
hs.add("am");
System.out.println("Size: "+hs.size());
System.out.println("Distinct Words : "+hs);
}
}
0 comments:
Post a Comment