Difference between ConcurrentHashMap and HashMap

Thread-safe i.e. synchronized
Low on performance because it is synchronized because sometimes threads have to wait
High on performance because it is non-synchronized and any threads can access it simultaneously.
ConcurrentHashMap we won’t get any exception while performing the same operation.
ConcurrentModificationException if two threads are simultaneously trying to modify or add contents of Object.
ConcurrentHashMap does not allow null values for key and value it tried to add null value we will get exception i.e. NullPointerException.
Null values are allowed for key and values in HashMap
ConcurrentHashMap is introduced in JDK 1.5
HashMap is introduced in JDK 1.2

Let’s see more:

%d bloggers like this: