← All topics
Quiz: Java Streams in Depth: questions with answers
10 questions, each with the answer and a short explanation.
Take the timed quiz + get a certificate →- Q1. What does this print? (code)
- Q2. What happens when Collectors.toMap(key, value) meets two elements with the same key?
- Q3. Which collector gives, for each city, how many students live there?
- Q4. What does this print? (code)
- Q5. What is special about partitioningBy compared with groupingBy?
- Q6. Which identity value is correct for reduce when multiplying numbers?
- Q7. What does this print? (code)
- Q8. Why use mapToInt(...).sum() instead of a Stream<Integer with reduce?
- Q9. You call count() on a stream and then call collect() on the same stream. What happens?
- Q10. A list holds sentences. You want one stream of all their words. Which operation do you use?