How hashtable is synchronized?why hashmap is not synchronized?Can we make hashmap synchronized?

Showing Answers 1 - 4 of 4 Answers

hashtable is a legacy class.every legacy class provides shnchroniztion.we can make hashmap sychornized but it call extra method.hashmap is not synchorinized but it part of collections and it enter null values.

  Was this answer useful?  Yes

Srinivas k

  • Dec 10th, 2005
 

Hashtable and HashMap both are Key Value pairs and  they function both the same way except in sychronization and HashMap accepts one null Key and many null values.

HashMap can be synchronized by

Map m = collections.synchronizeMap(hashMap);

ssubhajit

  • Nov 25th, 2009
 

Use the Code below to make a Hashmap synchronized ...
Hashmap objHashmap = Collections.synchronizedMap(new HashMap(....));

  Was this answer useful?  Yes

karthi1106

  • Dec 10th, 2009
 

Vector/Hashtable
Original classes before the introduction of Collections API. Vector & Hashtable are synchronized. Any  method that touches their contents is thread-safe.

ArrayList/HashMap
So if you don’t need a thread safe collection, use the ArrayList or  HashMap. Why pay the price of synchronization unnecessarily at  the expense of performance degradation.

  Was this answer useful?  Yes

Give your answer:

If you think the above answer is not correct, Please select a reason and add your answer below.

 

Related Answered Questions

 

Related Open Questions