The Growth Strategy: 1.5x Expansion
What you'll learn: You'll understand why ArrayList grows its internal capacity by approximately 50% when it runs out of space.
Why Not Double the Size?
When an ArrayList's backing array is full and you add another element, Java must create a larger array and copy everything over. The critical question: How much larger should the new array be?
You might think doubling the size makes sense, but ArrayList uses a more conservative approach: it grows by roughly 1.5x (or 50%).
The Growth Formula
Specifically, ArrayList calculates the new capacity as:
newCapacity = oldCapacity + (oldCapacity >> 1)
The >> 1 operation is a bit-shift that divides by 2, so this translates to:
newCapacity = oldCapacity + (oldCapacity / 2) = 1.5 × oldCapacity
Why 1.5x Instead of 2x?
Memory efficiency. Growing by 1.5x strikes a balance:
- Too small (like 1.1x): You'd resize too frequently, causing performance problems from repeated array copying
- Too large (like 2x): You waste significant memory with unused capacity
The 1.5x growth factor means:
- Fewer wasted empty slots compared to doubling
- Still amortizes the cost of copying over many additions (most
add()calls remain O(1)) - Better memory reuse patterns for the garbage collector
Visualizing Growth
If you start with capacity 10:
- First growth: 10 → 15
- Second growth: 15 → 22
- Third growth: 22 → 33
Compare this to doubling (10 → 20 → 40 → 80), and you can see how 1.5x saves memory.
Key Takeaway: ArrayList grows its capacity by approximately 1.5x when full, balancing performance (fewer resizes) with memory efficiency (less wasted space).