Streams & functional · interview question
What does this print?
What does this code output?Easy
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);
}
}Answer and explanation
Correct answer
A. ANA,BOB,DEE
Why
filter keeps the 3-letter names, map uppercases them, and joining(",") concatenates with commas.
References
Test yourself on Streams & functional
A free test with instant, explained results. No account needed.