HashSet

implements Set

  • Underlying Data Structure: Hashtable

  • Duplicates - NOT Allowed

  • Insertion Order - NOT Preserved (in order of hashcode)

  • null insertion - NOT Allowed

  • Best choice for: Search Operations

  • Worst choice for:

  • Constructors:

    1. HashSet h = new HashSet();
    2. HashSet h = new HashSet(int initialCapacity)
    3. HashSet h = new HashSet(int initialCapacity, float loadFactor)
    4. HashSet h = new HashSet(Collection C)
  • Default initial capacity: 16

  • Load factor/fill ratio: 0.75

  • New Capacity:

  • What will happen if we try to enter duplicate value for set? add() method will return false. šŸ‘†šŸ½ return type is boolean

  • Insertion order Object stored in order of hashcode() šŸ‘†šŸ½ Makes it best choice for search operations

Child classes/interfaces:

Linked HashSet


Children
  1. Linked HashSet

Backlinks