Summarizing the Die Frequencies

Lines 19–20 call Stream method collect to summarize the results into a Map<Integer, Long>. The first argument to Collectors method groupingBy (line 19) calls static method identity from interface Function, which creates a Function that simply returns its argument. This allows the actual random values to be used as the Map’s keys. The second argument to method groupingBy counts the number of occurrences of each key.

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.