Plain arrays have a fixed length. ArrayList wraps one for you and quietly reshuffles memory so the list never runs out of room.
1 import java.util
ArrayList lives in java.util — one import and plain arrays start looking clumsy.
2 add to the end
add(x) appends and grows the list; there is no size to declare in advance.
3 get by index
get(i) reads directly from the backing array — instant random access like arr[i].
4 remove shifts
remove(i) deletes a slot and slides everything after it one cell to the left.
An array that grows
import java.util1ArrayList lives in java.util — one import and plain arrays start looking clumsy. add to the end2add(x) appends and grows the list; there is no size to declare in advance. get by index3get(i) reads directly from the backing array — instant random access like arr[i]. remove shifts4remove(i) deletes a slot and slides everything after it one cell to the left. 4 building blocks make up An array that grows
Add, print, read one slot, remove the head — every call and the list state that follows it.
Console
output appears as the program runs…
The backing array keeps its four cells; ArrayList just tracks a smaller size and slides the rest left.
Drag to orbit the scene. Press Play to watch memory in action.
add with an index slots IN, pushing the rest right.
Your predicted output — one line per console line
Hint: add(1, 6) inserts AT index 1, shifting 7 right; remove(0) then deletes the first element.
Match each call to what it does.
5 conceptsTap a card to expand ?add(x)drops into place
?get(i)drops into place
?remove(i)drops into place
?set(i, x)drops into place
?size()drops into place
01ArrayList is an array in a trench coat — fixed capacity underneath, resizable behavior on top.
02add() appends in O(1); inserting in the middle shifts elements right.
03get(i) is instant because the backing array is contiguous.
04remove(i) shifts everything after i left by one cell.
05Always write the type argument: ArrayList<String>, not raw ArrayList.