Hashtable in Java

Posted on Updated on

Hashtable implements the Map interface and extends Dictionary class. Followings are the features of Hashtable…

  1. It stores key-value pairs.
  2. It contains unique key.
  3. It may have not have any null key or value.
  4. It is synchronized.

HashMap provides following constructors.

Constructor Description
Hashtable() Constructs a new, empty hashtable with a default initial capacity (11) and load factor (0.75)
Hashtable(Map map) Constructs a new hashtable with the same mappings as the given Map.
Hashtable(int initialCapacity) Constructs a new, empty hashtable with the specified initial capacity and default load factor (0.75). Throws IllegalArgumentException if the initial capacity is less than zero.
Hashtable(int initialCapacity, float loadFactor) constructs a new, empty Hashtable with the specified initial capacity and the specified load factor. Throws IllegalArgumentException if the initial capacity is less than zero, or if the load factor is nonpositive.

Example of HashTable

Output

Leave a Reply

Your email address will not be published. Required fields are marked *

Time limit is exhausted. Please reload CAPTCHA.