Interviews3 answers
What is the difference between Hashtable and hashmap in Java
3 Answers
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.
Synchronized
HashMap 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 & Values
Hashtable 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 guptaPosted Jan 23, 2016, 5:42 AM EST
http://javahungry.blogspot.com/2014/03/hashmap-vs-hashtable-difference-with-example-java-interview-questions.html
go through the above link..it will be very useful
Yashwanth MuthineniPosted Jul 13, 2015, 3:46 AM EDT
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 SharmaPosted Apr 15, 2014, 12:42 AM EDT

