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

Quiz: Java Streams in Depth · Question 1 of 10

What does this print? (code)

What does this print?

import java.util.*;
public class Main {
    public static void main(String[] args) {
        List.of(5, 12, 8, 20).stream()
            .filter(n -> { System.out.print(n + " "); return n > 10; })
            .findFirst();
        System.out.println();
    }
}
  1. A.5 12 8 20
  2. B.5 12
  3. C.12
  4. D.Nothing is printed
Answer & explanation

Correct answer: 5 12

Elements pass one at a time. 12 is the first that passes, and findFirst stops the stream, so 8 and 20 are never checked.

Can you get the rest right without peeking?

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

Start the quiz →