4 · Data & Collections · lesson 20 of 41

ArrayList & LinkedList

The two workhorse Lists — and when to use each.

Java
import java.util.*;

List<String> names = new ArrayList<>();
names.add("Ada");
names.add("Grace");
names.remove(0);

List<Integer> queue = new LinkedList<>();
queue.add(1); queue.add(2);
  • ▸ArrayList: fast random access, slow inserts in the middle.
  • ▸LinkedList: fast head/tail inserts, slow random access.
Key takeaways
  • ✓Prefer ArrayList by default.
  • ✓Use List<T> as the declared type; swap implementations freely.