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...!!! Share on X

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...!!! Share on X

 

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

Other Useful References:

Author

  • Deepak Verma

    Deepak Verma is a Test Automation Consultant and Software development Engineer for more than 10 years. His mission is to help you become an In-demand full stack automation tester. He is also the founder of Techndeck, a blog and online coaching platform dedicated to helping you succeed with all the automation basics to advanced testing automation tricks.

    http://Techndeck.com deepak.rkgit@gmail.com Verma Deepak