Why is better always to use custom initial capacity for ArrayList?
So, ArrayList have two main parameters.
First one is capacity which defined by default as 10. Capacity is used to create empty array thus help to optimize list by static creation
And size — is size of actual elements which list contains.
When size of list = capacity — list recreate himself as array with newCapacity.
newCapacity = newCapacity + (oldCapacity >> 1)
Which means each time when your list will be full java will create new array.
That's why for better performance is good to use expected initial capacity.
So, ArrayList have two main parameters.
First one is capacity which defined by default as 10. Capacity is used to create empty array thus help to optimize list by static creation
And size — is size of actual elements which list contains.
When size of list = capacity — list recreate himself as array with newCapacity.
newCapacity = newCapacity + (oldCapacity >> 1)
Which means each time when your list will be full java will create new array.
That's why for better performance is good to use expected initial capacity.