HashMap vs EnumMap

HashMap vs EnumMap

EnumMap was introduced in Java along with JDK 5 updates which is specialized Map implementation designed and optimized for using Java Enum as key. Java is having HashMap and lots of other concrete implementation of Map interface. So it is natural to ask question around EnumMap and other maps in interview. Most popular in all of these are HashMap vs EnumMap. Here we will be discussing differences and similarities of these two maps.

Differences between EnumMap and HashMap.

[table “” not found /]

Similarities between EnumMap and HashMap.

  1. Both EnumMap and HashMap allow null as valid value.
  2. Both these maps are not synchronized. We should manually synchronize both these map in case of multithreading environment.

Click here to understand more about EnumMap.

Leave a Reply

Your email address will not be published. Required fields are marked *