Java SE 8 Programmer II — Question 115

Given the code fragment:
List<String> empDetails = Arrays.asList("100, Robin, HR",
"200, Mary, AdminServices",
"101, Peter, HR");
empDetails.stream()
.filter(s-> s.contains("1"))
.sorted()
.forEach(System.out::println); //line n1
What is the result?

Answer options

Correct answer: A

Explanation

The code filters the list to include only those strings that contain '1', which results in '100, Robin, HR' and '101, Peter, HR'. These strings are then sorted and printed, leading to the output '100, Robin, HR 101, Peter, HR'. The other options do not reflect the correct filtering and sorting of the output.