← Quiz: Java 8 Lambdas and Streams: all 10 questions
Quiz: Java 8 Lambdas and Streams · 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<Integer> l = List.of(1, 2, 3, 4, 5);
System.out.println(l.stream().filter(x -> x % 2 == 1).map(x -> x * 10).toList());
}
}
- A.[10, 20, 30, 40, 50]
- B.[10, 30, 50]
- C.[20, 40]
- D.[1, 3, 5]
Answer & explanation
Correct answer: [10, 30, 50]
Keep odd numbers (1, 3, 5), then multiply each by 10.
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 →