toList() is a concise, unmodifiable alternative to collect(Collectors.toList()).
List<Integer> tripled = Stream.of(1, 2, 3)
.map(n -> n * 3)
.toList();
System.out.println(tripled);
[3, 6, 9]
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