mapToObj is the primitive-to-reference counterpart of boxed(), applying a function that turns each int into an object, such as a formatted label, in one step.
List<String> labels = IntStream.rangeClosed(1, 5)
.mapToObj(i -> "item-" + i)
.toList();
System.out.println("Labels: " + labels);
Labels: [item-1, item-2, item-3, item-4, item-5]
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-09-27