DEV Community


What are the differences between HashMap and Hashtable in Java?

・1 min read

Hashtables and HashMaps are both used to store data in key-value pairs. To store unique keys, both use the hashing approach. However, there are numerous distinctions between the HashMap and Hashtable classes, which are listed below.

HashMap is a non-synchronized data structure. It is not thread-safe and cannot be shared among several threads without the use of synchronization code.
One null key and numerous null values are allowed in HashMap.
HashMap is a brand-new class in JDK 1.2.
HashMap is a quick and fast algorithm.
This code can be used to make the HashMap synchronized : Map m = Collections.synchronizedMap(HashMap);
Iterator traverses the HashMap.
HashMap’s iterator is fail-safe.
AbstractMap is inherited by HashMap.

Read More:

Discussion (0)