Challenge 2: Partitioning Products by Stock Level — Possible Solution ==================================================================== PartitionDemo.java: import java.util.List; import java.util.Map; import java.util.stream.Collectors; public class PartitionDemo { record Product(String sku, String name, double price, int stock) {} public static void main(String[] args) { List products = List.of( new Product("A1", "Widget", 2.50, 25), new Product("A2", "Gadget", 9.99, 3), new Product("A3", "Gizmo", 15.00, 12), new Product("A4", "Doohickey", 4.75, 1) ); Map> partitioned = products.stream() .collect(Collectors.partitioningBy(p -> p.stock() > 10)); System.out.println("Above 10: " + partitioned.get(true)); System.out.println("10 or below: " + partitioned.get(false)); } } Output: Above 10: [Product[sku=A1, name=Widget, price=2.5, stock=25], Product[sku=A3, name=Gizmo, price=15.0, stock=12]] 10 or below: [Product[sku=A2, name=Gadget, price=9.99, stock=3], Product[sku=A4, name=Doohickey, price=4.75, stock=1]] Explanation: Collectors.partitioningBy() takes a Predicate and always produces a Map> with exactly two keys, true and false, grouping every stream element into one or the other based on the predicate's result. Unlike Collectors.groupingBy() with an arbitrary key, this always yields exactly two buckets, which fits perfectly here since the split is genuinely binary (above 10 vs. not). WHY THIS WORKS AS AN ANSWER ------------------------------ This uses Collectors.partitioningBy() correctly for a genuinely binary split, builds on the chapter's own record-based Product model, and prints both resulting groups to confirm the partition worked as described.