How to “group by” using Java Stream API

Ray Suliteanu
4 min readMar 12, 2021
Photo by Karim Sakhibgareev on Unsplash

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…

--

--