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 code fragment filters the list to only include strings that contain the character '1', which results in '100, Robin, HR' and '101, Peter, HR'. These two strings are then sorted in their natural order, which does not change their order as they are already sorted. Finally, they are printed out. Therefore, the output is '100, Robin, HR' followed by '101, Peter, HR'.
Answer A. Tested
Answer is A.
Answer: A
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); } }
Answer is A as String starting with 200 if filtered out since it doesn't contain 1.
Answer is A