ArrayList: how does the size increase?

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

    when a ArrayList is declared and initialized using default constructor, memory space for 10 elements will be created. now, when i add 11 th element, what happens is

    ArrayList create a new object with the following size

    i.e OldCapacity*3/2+1 = 10*3/2+1 =16

提交回复
热议问题