Converting an IntStream to a Stream<Integer>
We summarize the roll frequencies in this example by collecting them into a Map<Integer, Long>
in which each Integer
key is a side of the die and each Long
value is the frequency of that side. Unfortunately, Java does not allow primitive values in collections, so to summarize the results in a Map
, we must first convert the IntStream
to a Stream<Integer>
. We do this by calling IntStream
method boxed.
Get Java™ How To Program (Early Objects), Tenth Edition now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.