HashMap vs ConcurrentHashMap

HashMapConcurrentHashMap
Not Thread safeThread safe
Performance is HighRelatively Performance is low
While iterating other threads not allowed to modify and will not ConcurrentModificationExceptionWhile iterating other threads are allowed to modify no exceptions thrown
Iterator is FailFastIterator is fail safe
Null is allowed for both keys are valuesNull is not allowed in both keys and values
Introduced with java 1.2 verionIntroduced with Java 1.6 version

Leave a Comment