In Java, standard Arrays are fixed-length. Once instantiated, their size cannot change.
ArrayList Magic
An ArrayList is just a wrapper class around a standard array!
When it fills up, it transparently creates a new, larger array, copies elements, and updates its internal reference.
Tags
ArrayListArraymemory allocationO(N) copy
Primitive Array
int[] arr = new int[3];
Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: Index 3 out of bounds for length 3
ArrayList Object
ArrayList<Integer> list = new ArrayList<>(3);
O(N) Array Resize & Copy!
internal array: Object[] elementData
size: 0
capacity: 3
Simulation Control
Key Takeaway
ArrayList.add() is usually O(1) (fast), but when a resize is triggered, it becomes O(N) (slow) because it has to copy $N$ elements into the newly allocated block of memory.