Getting ready

There are two sets of collectors that use grouping—similar to the group by functionality of SQL statements—to present stream data as a Map object. The first set includes three overloaded groupingBy() factory methods:

  • Collector<T, ?, Map<K,List<T>>> groupingBy(Function<T,K> classifier): Creates a Collector object that collects the stream elements of the T type into a Map<K,List<T>> object using the provided classifier function to map the current element to the key in the resulting map.
  • Collector<T,?,Map<K,D>> groupingBy(Function<T,K> classifier, Collector<T,A,D> downstream): Creates a Collector object that collects the stream elements of the T type into a Map<K,D> object using the provided classifier function to map the current ...

Get Java 11 Cookbook now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.