It's the initial capacity, i.e. the number of items that ArrayList
will allocate to begin with as the internal storage of items.
ArrayList
can contain "any number of items" (as long you have the memory for it) and when doing large initial insertions you can tell ArrayList
to allocate a larger storage to begin with as to not waste CPU cycles when it tries to allocate more space for the next item.
Example:
ArrayList list = new ArrayList<Integer>(2);
list.add(1); // size() == 1
list.add(2); // size() == 2, list is "filled"
list.add(3); // size() == 3, list is expanded to make room for the third element
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…