How to “group by” using Java Stream API
4 min readMar 12, 2021
Recently I was trying to do essentially a “map-reduce” using the Java Stream API … counting the number of occurrences of words in some input. This wasn’t for some huge “big data” input set. Using Java Stream API was sufficient. But the Stream API doesn’t have a groupBy()
operation. While it does have map()
and reduce()
I couldn’t add a groupBy()
… at least not directly. Since it was not obvious I thought I’d write a…