As we already have HashMap, why would we use EnumMap?
HashMap
EnumMap
The Javadoc makes a pretty good argument:
Enum maps are represented internally as arrays. This representation is extremely compact and efficient. Implementation note: All basic operations execute in constant time. They are likely (though not guaranteed) to be faster than their HashMap counterparts.
Enum maps are represented internally as arrays. This representation is extremely compact and efficient.
Implementation note: All basic operations execute in constant time. They are likely (though not guaranteed) to be faster than their HashMap counterparts.
2.1m questions
2.1m answers
60 comments
57.0k users