Wednesday, 19 March 2014

Difference between Hashtable and Collections.synchronizedMap(HashMap)

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.

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:

Simplest way to display Server Time in JSP using js

THE BELOW CODE WORKS ONLY IN JSP : <html> <body > <table width="95%" border="1" cellpadding="1...