ArrayList: how does the size increase?

后端 未结 19 856
既然无缘
既然无缘 2020-11-29 18:11

I have a basic question on Java ArrayList.

When ArrayList is declared and initialized using the default constructor, memory space for 10 el

19条回答
  •  伪装坚强ぢ
    2020-11-29 18:36

    It will depend on the implementation, but from the Sun Java 6 source code:

    int newCapacity = (oldCapacity * 3)/2 + 1;
    

    That's in the ensureCapacity method. Other JDK implementations may vary.

提交回复
热议问题