Java Hashtable class implements a hash table, which maps keys to values. It inherits Dictionary class and implements the Map interface. Any non-null object can be used as a key or as a value. In this post, we will see “How to create a HashTable in Java and how to iterate its data using Set with an example?”

Simplest representation of Hashtable in Java with example... Check it out...!!! Click To Tweet

Key points to notice

  • HashTable is similar to Java HashMap but is synchronized.
  • HashTable stores key/value pair in a hash table.
  • HashTable class contains unique elements.
  • HashTable class doesn’t allow null key or value.

 

Syntax:

Example

 

Output:

Note: Previous value of key ‘age’ i.e ‘6’ in the above example is replaced with the new value i.e ‘7’.

 

Simplest representation of Hashtable in Java with example... Check it out...!!! Click To Tweet

 

Do you like this Post? – then check my other helpful posts:

Other Useful References: