Given the code fragment:
List
.filter(s-> s.contains("r"))
.sorted()
.forEach(System.out::println); //line n1
What is the result?
Given the code fragment:
List
.filter(s-> s.contains("r"))
.sorted()
.forEach(System.out::println); //line n1
What is the result?
The output will be filtered to include only the strings that contain the letter 'r', which are '100, Robin, HR', '101, Peter, HR', and '200, Mary, AdminServices'. After they are filtered, they are sorted lexicographically. The sorted order would be '101, Peter, HR' followed by '200, Mary, AdminServices'. Therefore, the result will be '101, Peter, HR' and '200, Mary, AdminServices'.
Answer is C, tested
correct
Answer is c tested. 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("r")) .sorted() .forEach(System.out::println); } }
C is correct.
Answer is C.