public static < T , K , R > Map < R , List < T > > toMapGroupBy ( Stream < T > stream , Function < T , R > groupingFunction ) { return stream . collect ( Collectors . groupingBy ( groupingFunction ) ) ; // to get a set: Collectors.groupingBy(groupingFunction, Collectors.toSet()) }
Collect a map by grouping based on the object s field .