Displaying the Summary Grouped by Starting Letter
Next, lines 27–37 group the key–value pairs in the Map wordCounts
by the keys’ first letter. This produces a new Map
in which each key is a Character
and the corresponding value is a List
of the key–value pairs in wordCounts
in which the key starts with the Character
. The statement performs the following tasks:
• First we need to get a Stream
for processing the key–value pairs in wordCounts
. Interface Map
does not contain any methods that return Stream
s. So, line 27 calls Map
method entrySet
on wordCounts
to get a Set
of Map.Entry objects that each contain one key–value pair from wordCounts
. This produces an object of type Set<Map.Entry<String, Long>>.
• Line 28 calls Set
method stream
to get ...
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.