Skip to content

ArrayList: a list that grows

Read · 1 of 3

add, get, set, size

ArrayList<Integer> list = new ArrayList<>(); makes an empty list of whole numbers (write Integer, not int, inside the < >).

list.add(x) puts x at the end, list.get(i) reads position i, list.set(i, x) replaces it and list.size() counts them.

for (int x : list) visits every value in order. It works on arrays too.