3 回答
TA贡献1828条经验 获得超6个赞
ArrayList = 10
LinkedList = no intial capacity
HashMap,LinkedHashMap,ConcurrentHashMap,HashSet,LinkedHashSet = 16
TreeSet = empty
TA贡献1851条经验 获得超4个赞
这里没有一个正确的答案,因为它取决于 Java 版本。例如RFR JDK-7143928 : (coll) Optimize for Empty ArrayList and HashMap made ArrayList
and HashMap
empty in the default in Java 8.
您必须检查 JDK 中每个提到的类的默认构造函数。理论上,这也可能因 JDK 构建(例如 Oracle、IBM、Azul...)而异,因为默认ArrayList
容量不是 Java 语言规范的一部分。
TA贡献1817条经验 获得超14个赞
1. Vector = 10
2. ArrayList = 10
3. LinkedList - does not have a capacity
4. HashMap = 16 (but with the default load factor of 0.75, only 12 can be populated before a resize will happen)
5. LinkedHashMap = 16 (read above)
6. ConcurrentHashMap = 16
7. HashSet = 16 (it's based on a HashMap)
8. LinkedHashSet = 16
9. TreeSet = does not have one
请注意,其中一些是懒惰的,并且所有这些都可能会因发行版的不同而有所变化。
添加回答
举报