Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
为什么 Java ArrayList 中的 ensureCapacity() 使用 const 1.5 或 (oldCapacity * 3)/2 + 1 扩展容量?
它有助于减轻如果数组被扩展一个元素而导致的时间指数增长。
您可以创建一个小容量甚至为 0 的阵列,小容量需要相对快速增长。