Differences between 'Hashtable' and 'Map'
1 posts in topic
Flat View  Flat View

Posted By:   Michael_Decker
Posted On:   Friday, November 30, 2001 04:57 AM


I 've tried to understand the difference between 'Hashtable'-Class and 'Map'-Class, but I failed.

What has 'Hashtable' got and what don't 'Map' have got?

Can anybody tell me, what are important differences?


Re: Differences between 'Hashtable' and 'Map'

Posted By:   Bozidar_Dangubic  
Posted On:   Friday, November 30, 2001 05:21 AM

first of all, Map is an interface while Hashtable is a concrete class. so you are better of comparing Hashtable and HashMap classes. the difference between them is that HashMap class is not synchronized while Hashtable class is. To get HashMap to be synchronized, you have to make the following call Map m = Collections.synchronizedMap(new HashMap(...));. so if you do not care about synchronized access to the collection (such as cases where collection is keeping read-only data) you should use HashMap because you eliminate the overhead of synchronization on access to the collection. if data in the collection is not read-only and is accessed by many threads and you want to preserve data integrity in the collection, you should use Hashtable.
About | Sitemap | Contact