Given the code fragment:
List
"200, Mary, AdminServices",
"101, Peter, HR");
empDetails.stream()
.filter(s-> s.contains("1"))
.sorted()
.forEach(System.out::println); //line n1
What is the result?
Given the code fragment:
List
"200, Mary, AdminServices",
"101, Peter, HR");
empDetails.stream()
.filter(s-> s.contains("1"))
.sorted()
.forEach(System.out::println); //line n1
What is the result?
The given code filters the elements of the list that contain the digit '1' and then sorts them. The filtered elements are '100, Robin, HR' and '101, Peter, HR'. After sorting, they remain in the same order because '100' comes before '101'. Hence, the output will be '100, Robin, HR' followed by '101, Peter, HR'.
Answer is A
A is correct 100, Robin, HR 101, Peter, HR
A is the correct answer A is the correct answer import java.util.Arrays; import java.util.List; public class Main { public static void main(String[] args) { 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); } }
A is correct, prints "100, Robin, HR 101, Peter, HR". Tested.
A is correct.