Java Streams learning path Level 1 This level · 11 of 25
Easy java streams

groupingBy versus partitioningBy

The 30 second answer

groupingBy takes a classifier and builds a map with whatever keys appear. partitioningBy takes a boolean predicate and always returns a map with both true and false keys. Both accept downstream collectors. For unordered parallel work there is also groupingByConcurrent.

Could you say this in an interview?

groupingBy(Function) → Map<K, List<T>> with arbitrary keys, only keys that occur. partitioningBy(Predicate) → Map<Boolean, List<T>>, always with both true and false.

Both accept downstream collectors. groupingByConcurrent exists for unordered parallel use.

Sources (1)
  1. Collectors.groupingBy / partitioningBy / groupingByConcurrentdocs.oracle.com
Previous
Next