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.
Share on Google Plus

About Pranav

This is a short description in the author block about the author. You edit it by entering text in the "Biographical Info" field in the user admin panel.
    Blogger Comment
    Facebook Comment


  1. Yo! Is it alright if I go a bit off topic? I'm trying to read your blog on my iPhone but it doesn't display properly, any suggestions? Thanks! Wendy

  2. I've been interested in this recent update and looks like I will look for some additional infomation. You really interested me.

  3. Hope you find it useful.

  4. hey Wendy let me took at why it is having problem with iphone.