Ctrl K
Java · Junior · Coding

There's a list of orders, and each order has a customer name and an amount of type long. Write a method totalByCustomer that takes this list and, using the Stream API, returns a map of customer name to the total amount of their orders.

~15 min by voice

How to approach it

They're checking whether you can build an aggregate with a Stream API collector (groupingBy + summingLong) instead of mutating an external map, whether you keep the long type, and whether you think about edge cases: a null list, a null customer, ordering.

Have you seen this question in a real interview?
Answers0
Avg. score—
Strong—
Practiced0
Topics
Similar questionsHow does Stream API execution work under the hood, and when would you use a parallel stream and when wouldn't you? Senior

Answer by voice

The interviewer will ask this question and listen. Think out loud and ask for a hint if you need one. When you're done, pause or tap “That's my answer”. In about a minute, your score and the points you covered show up here.

Sign in to answer

Best with headphones · ~15 min