The Hashset class

  • Hashset extends abstract set and implements the set interface.
  • It creates a collection that uses a hash table from storage.
  • Hash table stores information by using a mechanism called hashing.
  • In hashing, the informational content of a key is used to determine a unique value, called its hash code.
  • The hash code is then used as the index at which the data associated with the key is stored.
  • The advantage of hashing is that it allows the execution time of basic operations, such as add (), contains (), remove () and size () to remain constant even large sets.


The following constructors are defined in the hash class.

  1. Hashset (): it  constructs a default hash set
  2. Hashset (collection c): this initializes the hash set by using the elements of c
  3. Hashset (int capacity): this constructor initializes the capacity of the hash set to the value specified by the capacity.
  4. Hashset (int capacity, float fill ratio): this initializes both the capacity and fills ratio (also called load capacity) of the hash set from its arguments. The fill ratio must be between 0.0 and 1.0, and it determines how full the hash set can be before it is resized upward.  
  5. Specifically, when the number of elements is greater than, the capacity of the hash set multiplied by its fill ratio, then the hash set is said to be expended. For constructors that do not take a fill ratio, the default value of 0.75 is used.
  • Hash set does not define any additional methods beyond those provided by its super classes and interfaces.
  • Hash does no guarantee the order of its elements because the process of hashing does not usually bend itself to the creation of sorted sets. If we need a sorted storage, then another collection, such as Tree set is better choice.


The Hashset Class Homework Help