Saturday 25 July 2015

Difference between HashMap and ConcurrentHashMap



HashMap and ConcurrentHashMap are two different types of hashMap in java.Both implements Map interface but their internal working is different.


                                                     HashMap Vs ConcurrentHashMap



               HashMap


              ConcurrentHashMap
Null Value/Key


 It allow null value as well as key.
 It does not allow null values and keys.
 Thread Safe 


No.In order to make hashmap thread safe we need to use Collections.synchronized(Map) method
 Yes


Concurrency
 It does not allow concurrent access to multiple threads
 It allows a very high level of concurrency. Multiple threads can work on different portion of ConcurrentHashMap


 Iterator
 It implements fail fast.
 It implements fail safe.







Study internal working of both types of hashMap .It’s very important concept asked in interviews.

No comments:

Post a Comment