https://www.geeksforgeeks.org/differences-between-hashmap-and-hashtable-in-java/

HashMap and Hashtable store key and value pairs in a hash table. When using a Hashtable or HashMap, we specify an object that is used as a key and the value that you want to be linked to that key. The key is then hashed, and the resulting hash code is used as the index at which the value is stored within the table. Now let us discuss with the help of an example.

Hashmap vs Hashtable

Difference Between Hashmap and Hashtable

Now you must be wondering why HashTable doesn’t allow null and HashMap do?

The answer is simple. In order to successfully store and retrieve objects from a HashTable, the objects used as keys must implement the hashCode method and the equals method. Since null is not an object, it can’t implement these methods. HashMap is an advanced version and improvement on the Hashtable. HashMap was created later.

Example:

This article is compiled by Aditya Goel. Please write comments if you find anything incorrect, or you want to share more information about the topic discussed above.