ArrayList capacity increment equation

前端 未结 4 844
一整个雨季
一整个雨季 2021-01-19 14:21

In the JDK 1.7 into the ArrayList.java the method ensureCapacity increments the array capacity using the following expression: int newCapacity = oldCapaci

4条回答
  •  既然无缘
    2021-01-19 14:58

    From the ArrayList javadoc:

    The details of the growth policy are not specified beyond the fact that adding an element has constant amortized time cost.

    In other words, the books may be accurate for other implementations, but nothing's guaranteed - and the Java 7 source is still compliant with the docs, but shows the books to be overly specific.

提交回复
热议问题