Collections
ArrayList (dynamic array)
ArrayList (dynamic array)
List<Integer> list = new ArrayList<>();
list.add(10); // append, amortized O(1)
list.get(0); // O(1) random access
list.set(0, 20); // overwrite index 0
list.remove(list.size() - 1); // last is O(1); remove by index shifts → O(n)
list.contains(10); // linear scan O(n) — use a Set on hot paths
Collections.sort(list); // ascending, O(n log n)
List<Integer> fixed = List.of(1, 2, 3); // immutable — add() throws