ProgrammingHardProduct-company placement · Java

What is printed?

What is printed?
Stream.of(1, 2, 3).peek(System.out::print).map(x -> x * 2);
System.out.print("end");
  1. A. 123end
  2. B. 246end
  3. C. end
  4. D. 123246end

Correct answer: C. end

Intermediate operations such as peek and map do nothing until a terminal operation (forEach, collect, count…) runs. This pipeline has none, so peek's action never executes.

More OOP with C++ and Java questions

Exams that ask this topic