HashMap vs HashTable

Posted September 8, 2022 by Rohith and Anusha ‐ 1 min read

HashMap and Hashtable both are used to store data in key and value form. Both are using hashing technique to store unique keys.

There are many differences between HashMap and Hashtable classes that are Stated below.

HashMapHashtable
HashMap is non synchronized.It is not-thread safe and can’t be shared between many threads without proper synchronization code.
HashMap allows one null key and multiple null values.Hashtable doesn’t allow any null key or value.
HashMap is a new class introduced in JDK 1.2.Hashtable is a legacy class.
HashMap is fast.Hashtable is slow.
We can make the HashMap as synchronized by calling this code Map m = Collections.synchronizedMap(hashMap)Hashtable is internally synchronized and can’t be unsynchronized.
HashMap is traversed by Iterator.Hashtable is traversed by Enumerator and Iterator.
Iterator in HashMap is fail-fast.Enumerator in Hashtable is not fail-fast.
HashMap inherits AbstractMap class.Hashtable inherits Dictionary class.
quick-references blog hashmap hashtable differences

Subscribe For More Content