ArrayList: how does the size increase?

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

    In Jdk 1.6: New capacity = (Current Capacity * 3/2) + 1;

    In Jdk 1.7:

    int j = i + (i >> 1); this is same as New capacity = (Current Capacity * 1/2) + Current Capacity;

    ex:size will increase like :10-->15-->22-->33

提交回复
热议问题