← Quiz: Java 8 Lambdas and Streams: all 10 questions
Quiz: Java 8 Lambdas and Streams · Question 6 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("a", "bb", "ccc").stream().map(String::length).toList());
}
}
- A.[a, bb, ccc]
- B.6
- C.[1, 2, 3]
- D.[3, 2, 1]
Answer & explanation
Correct answer: [1, 2, 3]
String::length is a method reference for s -> s.length(), so each string becomes its length.
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 →