This class implements Set interface and supported by a hash table. It does not maintain the order of elements in collection. A collection that contains no duplicate elements.
package collection.demos;
import java.util.HashSet;
public class HashSetDemo {
public static void main(String[] args) {
HashSet<String> hs=new HashSet<String>();
hs.add("a");
hs.add("b");
hs.add("c");
hs.add("d");
hs.add("a");
hs.add("d");
hs.add("a");
hs.add("d");
hs.add("a");
System.out.println("Elements : "+hs);
}
}
package collection.demos;
import java.util.HashSet;
public class HashSetDemo {
public static void main(String[] args) {
HashSet<String> hs=new HashSet<String>();
hs.add("a");
hs.add("b");
hs.add("c");
hs.add("d");
hs.add("a");
hs.add("d");
hs.add("a");
hs.add("d");
hs.add("a");
System.out.println("Elements : "+hs);
}
}
Comments