HashSet Class
HashSet Class
The important points about Java HashSet class are:
- HashSet stores the elements by using a mechanism called hashing.
- HashSet contains unique elements only.
- HashSet allows null value.
- HashSet class is non synchronized.
- HashSet doesn't maintain the insertion order. Here, elements are inserted on the basis of their hashcode.
- HashSet is the best approach for search operations.
- The initial default capacity of HashSet is 16, and the load factor is 0.75.
Constructors
HashSet() : It is used to construct a default HashSet.HashSet(int capacity) : It is used to initialize the capacity of the hash set to the given integer value capacity. The capacity grows automatically as elements are added to the HashSet.
HashSet(int capacity, float loadFactor) : It is used to initialize the capacity of the hash set to the given integer value capacity and the specified load factor.
Extra Methods apart from Collection
- iterator() : return Iterator<E> object
Comments
Post a Comment