Collections Początkujący

Create immutable lists in one clean expression.

✕ Java 8
List<String> list =
    Collections.unmodifiableList(
        new ArrayList<>(
            Arrays.asList("a", "b", "c")
        )
    );
✓ Java 9+
List<String> list =
    List.of("a", "b", "c");
Widzisz problem z tym kodem? Daj nam znać.
📏

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.

Stare podejście
Verbose Wrapping
Nowoczesne podejście
List.of()
Od JDK
9
Poziom trudności
Początkujący
Immutable list creation
Dostępne

Widely available since JDK 9 (Sept 2017)

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.

Udostępnij 𝕏 🦋 in