HashSet is the direct subclass of Set interface , HashSet doesn’t allow duplicates element insertion and insertion order is not preserved.
- Underlined data structure is HashTable.
- HashSet doesn't allow duplicates.
- Insertion order is not preserved.
- Null insertion is allowed.
- Heterogeneous objects are allowed.
- Implements Serializable and clonable interfaces.
Constructor in HashSet
HashSet hs=new HashSet(); // creates an empty HashSet
HashSet hs=new HashSet(int initialCapacity);
//Creates and empty HashSet with passed initialCapacity and default load factor 0.75.
HashSet hs=new HashSet(Collection c);
//Creates a HashSet representation of Passed collection object.
HashSet hs=new HashSet(int initialCapacity, float loadFactor);
//creates an empty HashSet with given initialCapacity and given loadFactor.