HashSet Class

 HashSet Class

The important points about Java HashSet class are:

  1. HashSet stores the elements by using a mechanism called hashing.
  2. HashSet contains unique elements only.
  3. HashSet allows null value.
  4. HashSet class is non synchronized.
  5. HashSet doesn't maintain the insertion order. Here, elements are inserted on the basis of their hashcode.
  6. HashSet is the best approach for search operations.
  7. 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

Popular posts from this blog

Software Engineering PPT

ERP Software Links

Include Tag JSP