Wednesday, May 2, 2007

What is the difference between Hashtable and HashMap?

Both Hashtable and HashMap store key-value pairs but they have following distinctive features:
-Hashtable is synchronized while HashMap is not.In such a case Hashtable has performance overhead and should only be used when data is to be accessed in thread safe manner.
-In Hashtable any non-null object can be used as a key or as a value but HashMap allows null keys and values.

2 comments :

Saurabh on February 20, 2008 at 11:08 PM said...

Cool.

JP @ what is hashmap in java on July 9, 2011 at 2:35 AM said...

great article , just to add iterator of hashmap are fail-fast so they will fail as soon as they detect that hashmap is structurally modified.

Thanks
difference between hashtable and hashmap in Java

 

Disclaimer
Interview Questions On Java,Java EE Copyright © 2017. Reads: best tracker