java - 为什么使用 EnumMap 而不是 HashMap

标签 java hashmap enum-map

既然我们已经有了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/

相关文章:

Java (Android) HTTP 发布到 PHP 页面

java - Mockito 匹配任何类参数

java - 是否可以使用 Postman Chrome 扩展程序发送 HashMap ?

java - EnumMap<Enum,String> (OneToMany) 的 Hibernate 注解

java - JAVA动态创建arrayList

java - 为什么 Unmarshaller 行为不一致?

algorithm - 在 O(logN) 时间复杂度中使用 HashMap 对节点链表进行二进制搜索

java - HashMap 键不是随机的

Java 8 : Transform EnumMap<ExampleEnum, 字符串> 到映射<字符串,对象>

java - 将原始值存储在 EnumMap 中