I'm looking at the docs for the IntStream
, and I see an toArray
method, but no way to go directly to a List<Integer>
Surely there is a way to convert a Stream
to a List
?
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.
Collected from the Internet
Please contact javaer1[email protected] to delete if infringement.
Comments