既然我们已经有了HashMap
,为什么还要使用EnumMap
呢?
最佳答案
Javadoc提出了一个很好的论点:
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.
关于java - 为什么使用 EnumMap 而不是 HashMap,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53406636/