🎙 Free live masterclass · Sun, 29 Nov, 7:00 pm IST · Java Full Stack roadmap Register free →
Skills101
← 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 →
  1. Q1. What does this print? (code)
  2. Q2. What happens when Collectors.toMap(key, value) meets two elements with the same key?
  3. Q3. Which collector gives, for each city, how many students live there?
  4. Q4. What does this print? (code)
  5. Q5. What is special about partitioningBy compared with groupingBy?
  6. Q6. Which identity value is correct for reduce when multiplying numbers?
  7. Q7. What does this print? (code)
  8. Q8. Why use mapToInt(...).sum() instead of a Stream<Integer with reduce?
  9. Q9. You call count() on a stream and then call collect() on the same stream. What happens?
  10. Q10. A list holds sentences. You want one stream of all their words. Which operation do you use?