List (ArrayList) in Java

From the Java cheat sheet · Arrays & Collections · verified Jul 2026

List (ArrayList)

The most-used resizable, ordered collection.

java
// Quick Reference
List<String> list = new ArrayList<>();
list.add("a");  list.get(0);
list.remove("a");  list.size();
var fixed = List.of("x", "y");   // immutable
💡 Program to the List interface; swap ArrayList for LinkedList without changing callers.
⚡ List.of(...) creates a compact immutable list - great for constants.
📌 remove(int) removes by index; remove(Object) removes by value - watch Integer lists.
🟢 The diamond <> on the right infers the type: new ArrayList<>().
listarraylist

More Java tasks

Back to the full Java cheat sheet