What is the output of the following?.
public class Main { public static void main(String[] args) { Stream<Integer> is = Stream.of(8, 6, 9); Comparator<Integer> c = (a, b) -> b - a; // r1 is.sorted(c).forEach(System.out::print); // r2 } }
B.
First, remember that you are supposed to assume missing imports are present so you can act as if java.util and java.util.stream are imported.
This code does compile.
Line r1 is a valid lambda definition of a Comparator.
Line r2 is valid code to sort a stream in a descending order and print the values.
Therefore, Option B is correct.