Welcome to my blog, hope you enjoy reading
RSS

Saturday 5 January 2013

What are the differences between HashMap and Hashtable?


What are the differences between HashMap and Hashtable?

Lets see what are the differences we can see in HashMap and Hashtable.
1. Synchronization :
Hashtables are synchronized , it means at one point of time only one thread can modify a Hashtable. i.e any thread before performing an update on a hashtable will be acquiring a lock on the object while others will wait for lock to be released.
Hashmap is not synchronized , but we can make it synchronized.
2. Fail-safe:
Iterator of HashMap is fail-safe but the enumerator for the Hashtable is not fail-safe. Lets see what exactly fail-safe is. If an iterator has been created on a collection object and some other thread tries to modify this object , a concurrent modification exception will be thrown. So fail safe is like ability of system to fail but it wont produce some catastrophic results.
3. null values
Hashtable doesn’t allow null but Hashmap allows null values.

0 comments: