DifferenceS :
1.The HashMap class is roughly equivalent to Hashtable, except that it is non synchronized and permits
nulls. (HashMap allows null values as key and value whereas Hashtable doesn't allow nulls).
2.One of the major differences between HashMap and Hashtable is that HashMap is non
synchronized whereas Hashtable is synchronized.
Which means Hashtable is thread-safe and can be shared between multiple threads but HashMap can not
be shared between multiple threads without proper synchronization. Java 5 introduces
ConcurrentHashMap which is an alternative of Hashtable and provides better scalability than Hashtable in
Java.
1.The HashMap class is roughly equivalent to Hashtable, except that it is non synchronized and permits
nulls. (HashMap allows null values as key and value whereas Hashtable doesn't allow nulls).
2.One of the major differences between HashMap and Hashtable is that HashMap is non
synchronized whereas Hashtable is synchronized.
Which means Hashtable is thread-safe and can be shared between multiple threads but HashMap can not
be shared between multiple threads without proper synchronization. Java 5 introduces
ConcurrentHashMap which is an alternative of Hashtable and provides better scalability than Hashtable in
Java.
3.HashTable is legacy class promoted into collection framework. It got its own extra features like enumerators.
NOTE:
HashMap can be synchronized by
Map m = Collections.synchronizeMap(hashMap);
No comments:
Post a Comment