Practice ยท 2 of 3
toMap with a Merge Function
- record Sale(String region, int amount) in Solution
- static Map<String, Integer> totalsByRegion(List<Sale> sales) โ sum
amounts per region using Collectors.toMap with Integer::sum as the
merge function.
- static Map.Entry<String, Integer> topRegion(List<Sale> sales) โ
returns the region's entry with the highest total (ties: smallest
region name wins).
Duplicate keys without a merge function throw IllegalStateException โ
the tests make sure you used one.
Difficulty: intermediate
Press Submit to check your solution.
Back to lesson: Practice: Functional Lab