Skip to content
Sharp

Streams & functional · interview question

What does this print?

What does this code output?Easy
java
public class Main {
    public static void main(String[] args) {
        List<String> names = List.of("Ana", "Bob", "Cy", "Dee");
        String result = names.stream()
            .filter(n -> n.length() == 3)
            .map(String::toUpperCase)
            .collect(Collectors.joining(","));
        System.out.println(result);
    }
}
Choose one answer
Answer and explanation

Correct answer

A. ANA,BOB,DEE

Why

filter keeps the 3-letter names, map uppercases them, and joining(",") concatenates with commas.

Test yourself on Streams & functional

A free test with instant, explained results. No account needed.

Start free test
All Streams & functional questions →