ArrayList: how does the size increase?

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

    Up to JDK 6 the the capacity grow with formula newCapacity = (oldCapacity * 3/2) + 1.

    In JDK 7 and above the formula changes to newCapacity = oldCapacity + (oldCapacity >> 1).

    So if initial capacity is 10 then new capacity will be 16 in JDK6 and 15 in above JDK7

提交回复
热议问题