ArrayList: how does the size increase?

后端 未结 19 859
既然无缘
既然无缘 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:27

    From JDK source code, I found below code

    int oldCapacity = elementData.length;
    int newCapacity = oldCapacity + (oldCapacity >> 1);
    

提交回复
热议问题