ArrayList capacity increment equation

前端 未结 4 823
一整个雨季
一整个雨季 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:34

    In Java 6 newCapacity is calculated as => int newCapacity = (oldCapacity * 3)/2 + 1;

    In Java 7 newCapacity is calculated as => int newCapacity = oldCapacity + (oldCapacity >> 1)

提交回复
热议问题