ArrayList Growth Factor

ArrayList is a dynamic array which means the size of arraylist increases as the elements are added. The number by which the size is increased is known as Growth Factor.

In ArrayList the Growth factor is 1.5, which means everytime the size of list is to be increased it is increased by 1.5.

Example:- If current size of list is 10 and the size of list is to be increased then after increasing it will become 1.5*10 = 15.

Let us look at internal implementation of arraylist’s size being increased :-

int oldCapacity = elementData.length;
int newCapacity = oldCapacity + (oldCapacity >> 1);

Here ‘>>’ is a right shift bitwise operator used to shift the binary representation of number to right by one place. Example:- if we do (8>> 1) then it means (100 >> 1) = (10) = 4, where ‘100’ is binary representation of 8 and ’10’ is binary representation of 4. In short ‘>>’ operator divides the number by 2.

So in the formula “newCapacity = oldCapacity + (oldCapacity >> 1)” we are halving the oldCapacity and adding it to itself which is equivalent to saying 1.5 * oldCapacity.

Leave a Comment