Java 16: Stream.toList() shortcut

toList() is a concise, unmodifiable alternative to collect(Collectors.toList()).

Code
List<Integer> tripled = Stream.of(1, 2, 3)
        .map(n -> n * 3)
        .toList();
System.out.println(tripled);
Output
[3, 6, 9]
Advertisement

Run this yourself in the Online Java Compiler, spin up a live REST API in the API Sandbox, or practise with Java interview questions.

Published 2026-07-26