// Created on savesnippets.com · https://savesnippets.com/TQcu7srXBW9hHj import java.util.*; import java.util.stream.*; import static java.util.stream.Collectors.*; class Demo { void example() { var nums = List.of(1, 2, 3, 4, 5, 6, 7, 8, 9, 10); Map> split = nums.stream() .collect(partitioningBy(n -> n % 2 == 0)); System.out.println(split.get(true)); // [2, 4, 6, 8, 10] System.out.println(split.get(false)); // [1, 3, 5, 7, 9] // With downstream — count instead of collect Map counts = nums.stream() .collect(partitioningBy(n -> n > 5, counting())); System.out.println(counts); // {false=5, true=5} } }