Sobes.tech
Junior

What is the initial size of an ArrayList?

sobes.tech AI

Answer from AI

By default - 10.

When adding the first element, if the internal array is empty, an array of size 10 is created. If the array is initially created with zero capacity, then upon the first addition, an array of size 10 is also created.

// Example of creating an ArrayList with zero capacity
ArrayList<String> list = new ArrayList<>(0);
// When adding the first element (for example, "hello")
// an internal array of size 10 will be created.
list.add("hello");