🎙 Free live masterclass · Sun, 29 Nov, 7:00 pm IST · Java Full Stack roadmap Register free →
Skills101
← 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());
    }
}
  1. A.[a, bb, ccc]
  2. B.6
  3. C.[1, 2, 3]
  4. 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 →