← 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));
}
}
- A.24
- B.9
- C.0
- 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 →