Collectors.partitioningBy() is a factory method in Java's Collectors class that splits stream elements into two groups based on a predicate, storing results in a Map<Boolean, List<T>>. The map always has exactly two keys—true and false—making it useful when you need both the matching and non-matching elements after filtering. Unlike groupingBy() or toMap(), partitioningBy() does not support a custom map supplier; the map implementation is fixed internally.

1m watch time

Sort: