Immutable list creation
Create immutable lists in one clean expression.
Code Comparison
✕ Java 8
List<String> list =
Collections.unmodifiableList(
new ArrayList<>(
Arrays.asList("a", "b", "c")
)
);
✓ Java 9+
List<String> list =
List.of("a", "b", "c");
Why the modern way wins
One call
Replace three nested calls with a single factory method.
Truly immutable
Not just a wrapper — the list itself is immutable.
Null-safe
Rejects null elements at creation time, failing fast.
Old Approach
Verbose Wrapping
Modern Approach
List.of()
Since JDK
9
Difficulty
beginner
JDK Support
Immutable list creation
Available
Widely available since JDK 9 (Sept 2017)
How it works
List.of() creates a truly immutable list — no wrapping, no defensive copy. It's null-hostile (rejects null elements) and structurally immutable. The old way required three nested calls.