Consider: Stream.of(1, 2, 3).map(x -> { System.out.println(x); return x * 2; }).collect(Collectors.toList()); What will print?
A1 2 3
B2 4 6
CNothing until the collect operation completes
D1 2 3 2 4 6
Correct Answer:
A. 1 2 3
EXPLANATION
map() is an intermediate operation. The println executes because collect() is a terminal operation that triggers evaluation. It prints 1, 2, 3 (the original values).
Which of the following correctly uses method reference with constructor?
AString::new
Bnew String::
CString->new
Dnew::String
Correct Answer:
A. String::new
EXPLANATION
Constructor method references use ClassName::new syntax. String::new refers to the String constructor and can be used wherever a Supplier<String> is expected.
Consider: Function curried = a -> b -> a + b; What is this pattern called?
AHigher-order function with currying
BNested lambda expression
CFunction composition
DStream reduction
Correct Answer:
A. Higher-order function with currying
EXPLANATION
This is a curried function - a higher-order function that takes one argument and returns another function taking the next argument. It transforms multi-argument functions into sequences of single-argument functions.