ArrayList: how does the size increase?

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

    Default capacity of ArrayList is 10. Once the Capacity reaches its maximum capacity, Size of the ArrayList will be 16, once the capacity reaches its maximum capacity of 16, size of the ArrayList will be 25 and keep on increasing based on Data size.....

    How? Here is the Answer and Formula

    New capacity = (Current Capacity * 3/2) + 1
    

    So, if the default capacity is 10, then

    Current Capacity = 10
    New capacity = (10 * 3/2) + 1
    Output is 16
    
    0 讨论(0)
提交回复
热议问题