mapMulti pushes zero-or-more results per element without creating intermediate streams.
List<Integer> nums = List.of(1, 2, 3);
List<Integer> withDoubles = nums.stream()
.<Integer>mapMulti((n, consumer) -> {
consumer.accept(n);
consumer.accept(n * 10);
})
.toList();
System.out.println(withDoubles);
[1, 10, 2, 20, 3, 30]
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