🎙 Free live masterclass · Sun, 29 Nov, 7:00 pm IST · Java Full Stack roadmap Register free →
Skills101
← Quiz: Java 8 Lambdas and Streams: all 10 questions

Quiz: Java 8 Lambdas and Streams · Question 4 of 10

What does this print? (code)

What does this print?

import java.util.*;
public class Main {
    public static void main(String[] args) {
        System.out.println(List.of(2, 3, 4).stream().reduce(0, Integer::sum));
    }
}
  1. A.24
  2. B.9
  3. C.0
  4. D.[2, 3, 4]
Answer & explanation

Correct answer: 9

reduce adds the numbers starting from 0: 2 + 3 + 4 = 9.

Can you get the rest right without peeking?

Take the timed Quiz: Java 8 Lambdas and Streams quiz free. Pass it to earn XP and count towards your certificate.

Start the quiz →