Wednesday, 14 January 2015

Difference between HashMap and HashTable

Both HashTable and HashMap implements Map interface but there are some differences between these two.It is one of the most popular questions asked in interview.So prepare well.

                                                    HashMap Vs HashTable




 HashMap
  HashTable

Synchronization or thread-safe
HashMap is not synchronized.hence It is better for non-threaded applications.


 HashTable is synchronized.This makes it better for multi-threading applications.

Iteration methods

 HashMap uses Iterator interface for iteration.
 HashTable use enumeration interafce for iterating the values.

Null Values/Keys

 HashMap allows one null key and any number of null values.
 whereas HashTable does not alloe null key and null values.

Performance

 HashMap is faster and uses less memory as it is not synchronized.
 HashTable takes more memory and slower than HashMap in performance.


Fail Fast Iterator

The iterator in HashMap is fail fast.The enumeration in HashTable is not fail fast.


Make sure you study this well.Happy Reading... :)

No comments:

Post a Comment