IntStream::boxed
IntStream::boxed
turns an IntStream
into a Stream<Integer>
, which you can then collect
into a List
:
theIntStream.boxed().collect(Collectors.toList())
The boxed
method converts the int
primitive values of an IntStream
into a stream of Integer
objects. The word “boxing” names the int
⬌ Integer
conversion process. See Oracle Tutorial.
Java 16 and later
Java 16 brought the shorter toList
method. Produces an unmodifiable list. Discussed here.
theIntStream.boxed().toList()