ArrayList Default Size

Arraylist is a dynamic array whose size increases as we add more elements to it.

When an ArrayList is created without specifying its size then the size of Arraylist initially is zero. But when we add the first element to the list then size of ArrayList is increased to 10.

This can be shown by the internal code of ArrayList:

    private static final int DEFAULT_CAPACITY = 10;
    private static final Object[] DEFAULTCAPACITY_EMPTY_ELEMENTDATA = {};
    public ArrayList() {
        this.elementData = DEFAULTCAPACITY_EMPTY_ELEMENTDATA;
    }

Now when the add() function is called to add any value, then the size of arraylist is grown to 10 and the value is added to ArrayList internally. The first index of ArrayList will contain the added value and rest of indexes will be empty.

Now let us see the Growth Factor of ArrayList.

Leave a Comment