Skip to content

HashTable

Vishnu Garg edited this page Aug 2, 2018 · 1 revision

HashTable implementation and working

Hashtable is an implementation of a key-value pair data structure in java. You can store and retrieve a ‘value’ using a ‘key’ and it is an identifier of the value stored. It is obvious that the ‘key’ should be unique.

java.util.Hashtable extends Dictionary and implements Map. Objects with non-null value can be used as a key or value. Key of the Hashtable must implement hashcode() and equals() methods. By the end of this article you will find out the reason behind this condition.

Working of Hashtable depends on various parameters. Initial capacity, load factor, size and Threshold value are the parameters which affect Hashtable performance.

  • Initial Capacity: This is the capacity of Hashtableto store number of key value pairs when it is instantiated. Default capacity is 11
  • Load Factor: A parameter responsible to determine when to increase size of Hashtable. Default load factor is 0.75
  • **Size **: number of key value pairs in Hashtable.
  • Threshold value: When number of key value pairs is more than threshold value, then Hashtable is resized.
  • Its uses the same algorithms as HashMap, doesnt not allow one null key and sysnchronized New capacity in java Hashtable is calculated as follows: int newCapacity = oldCapacity * 2 + 1;

**Creation **
Constructor are

Hashtable( );
Hashtable(int capacity);
Hashtable(int capacity, float loadfactor);

Clone this wiki locally