← Quiz: Java 8 Lambdas and Streams: all 10 questions
Quiz: Java 8 Lambdas and Streams · Question 9 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(5, 3, 5, 1, 3, 9).stream().distinct().sorted().limit(3).toList());
}
}
- A.[5, 3, 1]
- B.[1, 3, 5]
- C.[1, 3, 3]
- D.[5, 3, 5]
Answer & explanation
Correct answer: [1, 3, 5]
distinct leaves 5, 3, 1, 9; sorted gives 1, 3, 5, 9; limit(3) keeps the first three.
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 →