What is the output of the following? “`java Stream.of(1, 2, 3).reduce(0, Integer::sum) “`

Java Professional Medium

Java Professional — Medium

What is the output of the following? “`java Stream.of(1, 2, 3).reduce(0, Integer::sum) “`

Key points

  • The reduce method combines all elements of the stream into a single result.
  • The `Integer::sum` method reference is used to perform the sum operation.
  • The initial value of 0 is added to the sum of the elements.
  • The correct answer is 6, which is the sum of 1, 2, and 3.

Ready to go further?

Related questions