Question 1
What is the output of the following program? ```java import java.util.stream.Stream; public class Main { public static void main(String[] args) { StringBuilder sb = new StringBuilder(); Stream.of(1, 2, 3) .peek(sb::append) .filter(n -> n % 2 == 1) .forEach(n -> { }); System.out.println(sb); } } ```
A. An empty line
The forEach terminal forces the pipeline to execute, so output is produced.
B. Compilation fails
The pipeline is well formed and compiles.
C. 13
This is what peek would record if placed after the filter; before it, every element is seen.
D. 123Correct answer
Correct: peek runs before filtering, so it captures all three elements in order.
Explanation
peek observes every element that flows through it at its position in the pipeline, and here it sits before the filter, so it sees all elements even those later discarded. A terminal operation drives the pipeline to run.