HashMap vs HashTable
What is the difference between a HashMap and HashTable?
java.util.HashMapallows null keys and values whereas ajava.util.Hashtabledoes not.HashMapis unsynchronized and therefore much faster. However, its not suitable when there are multiple threads inserting/getting from the map.HashTableis synchronized and its slower because of overhead involved in maintaining locks.
Hashtable is old and is considered legacy. java.lang.concurrent.ConcurrentHashMap should be used instead. ConcurrentHashMap only locks certain section of HashMap during insertion. The remaining section of the map can be accessed lock free and therefore is as fast as a regular HashMap.
Written on August 9, 2015