QuestionQ33

Working with Streams and Lambda expressions

Consider:

Question Image

What is the output?

  • A {bicycle=7, car=7, motorcycle=7, truck=7}
  • B {3:bicycle, 0:car, 6:motorcycle, 5:truck}
  • C Compilation fails.
  • D {bicycle=1, car=3, motorcycle=1, truck=2}
  • E {bicycle, car, motorcycle, truck}
Explanation

Collectors.groupingBy(Function.identity(), Collectors.counting()) groups each identical string and counts its occurrences. The resulting counts are bicycle=1, car=3, motorcycle=1, and truck=2.

Community Discussion

No comments yet. Be the first to start the discussion!