Java HashMap vs HashTable
Last updated on
Java HashMap Interview Questions
Both HashMap and HashTable store key/pair values. They differ in mainly in thread safety, performance, and acceptance of null keys.
HashTable is the synchronized version of HashMap. This means HashTable is thread safe whereas HashMap is not.
With that said, you can easily "synchronize" a HashMap like:
Map m = Collections.synchronizedMap(hashMap)
HashMap allows a null key. HashTable does not.
Synchronized operations are inherently slow. Even if thread safety is important to you, a HashMap can easily be converted int a thread-safe alternative.
A HashMap is also designed to fail fast whereas a HashTable will not.
Share your thoughts