Java OCA OCP Practice Question 2534

Question

Assume that today is June 1, 2020. What is the result of the following?

Stream<LocalDate> s = Stream.of(LocalDate.now()); 
UnaryOperator<LocalDate> u = l -> l; 
s.filter(l -> l != null).map(u).peek(System.out::println); 
  • A. 2020-05-01
  • B. B. 2020-06-01
  • C. There is no output.
  • D. The output is something other than 2020-05-01 or 2020-06-01.
  • E. The code does not compile.
  • F. An exception is thrown.


C.

Note

There is no terminal operation.

Since the intermediate operations use lazy evaluation, they wait for a terminal operation to run.

Since there is no terminal operation, peek() never runs.




PreviousNext

Related