What is the difference between Hashtable and hashmap in Java

Satheesh Reddy

Satheesh Reddy

Jan 21, 2014

    Legacy HashMap was introduced in JDK 1.2 and extends AbstractMap class whereas Hashtable is a legacy class which initially was not part of collection framework. Later from JDK 1.2 it became part of Collection framework and implemented Map interface. Dictionary is the super class of Hashtable class.SynchronizedHashMap is not synchronized whereas Hashtable is synchronized. But you can explicitly synchronize HashMap. Hence, Hashtable is thread-safe whereas HashMap is not thread-safe.Keys & ValuesHashtable does not allow null keys and null values whereas HashMap allows to store one null key and any number of null values.Read full article at Difference between Hashmap and Hashtable in Java

    amit gupta
    January 23, 2016

    http://javahungry.blogspot.com/2014/03/hashmap-vs-hashtable-difference-with-example-java-interview-questions.htmlgo through the above link..it will be very useful

    Yashwanth Muthineni
    July 13, 2015

    There are several differences between HashMap and Hashtable in Java:Hashtable is synchronized, whereas HashMap is not. This makes HashMap better for non-threaded applications, as unsynchronized Objects typically perform better than synchronized ones. Hashtable does not allow null keys or values. HashMap allows one null key and any number of null values. One of HashMap's subclasses is LinkedHashMap, so in the event that you'd want predictable iteration order (which is insertion order by default), you could easily swap out the HashMap for a LinkedHashMap. This wouldn't be as easy if you were using Hashtable.

    Munesh Sharma
    April 15, 2014