Initial Capacity and the Default Constructor
What you'll learn: How an ArrayList starts out when you create it using the no-argument constructor.
When you write ArrayList<String> list = new ArrayList<>();, you're using the default constructor—the one that takes no arguments. But what happens behind the scenes?
The Empty Start
When you call new ArrayList<>() with no arguments, the ArrayList doesn't immediately allocate a full-sized array. Instead, it starts in an optimized "empty" state. The backing array is either empty or very small to save memory.
First Addition Triggers Allocation
The moment you add your first element, the ArrayList allocates an initial backing array. By default, this initial capacity is 10 elements. This means the backing Object[] array gets sized to hold 10 elements, even though you've only added one.
Think of it like reserving a parking lot: when the first car arrives, you set up spaces for 10 cars, anticipating more will come soon. This avoids constantly resizing.
Why Start at 10?
The initial capacity of 10 is a trade-off. Too small (like 2), and you'd resize constantly as elements are added. Too large (like 1000), and you'd waste memory if the list stays small. Java's designers chose 10 as a reasonable middle ground for typical use cases.
What "Capacity" Really Means
Capacity is different from size. The size is how many elements are actually in the list. The capacity is how many the backing array can hold before needing to grow. A new ArrayList has size 0 but gains capacity 10 on first use.
Key Takeaway: When you create an ArrayList with no arguments, it starts empty and allocates an initial capacity of 10 elements when you add the first item—balancing memory efficiency with growth performance.