Collections Framework 1

Lesson 16 of 20

Meet ArrayList: a resizable array that grows as you add, with add, get, remove and size at your fingertips.

The big picture

An array that grows

Plain arrays have a fixed length. ArrayList wraps one for you and quietly reshuffles memory so the list never runs out of room.

import java.util

ArrayList lives in java.util — one import and plain arrays start looking clumsy.

add to the end

add(x) appends and grows the list; there is no size to declare in advance.

get by index

get(i) reads directly from the backing array — instant random access like arr[i].

remove shifts

remove(i) deletes a slot and slides everything after it one cell to the left.