nerdexam
Oracle

1Z0-809 · Question #109

1Z0-809 Question #109: Real Exam Question with Answer & Explanation

The correct answer is B. Replace line n1 with: IntFunction<IntUnaryOperator> inFu = x -> y -> x*y; Replace line n2 with: IntStream newStream = stream.map(inFu.applyAsInt(10));. See the full explanation below for the reasoning.

Question

Given:
IntStream stream = IntStream.of(1,2,3);
IntFunction<Integer> inFu = x -> x * x;//line n1
IntStream newStream = stream.map(inFu.apply(10));//line n2
newStream.forEach(System.out::print);
Which modification enables the code fragment to compile?

Options

  • AReplace line n1 with: IntFunction<UnaryOperator> inFu = x -> y -> x*y;
  • BReplace line n1 with: IntFunction<IntUnaryOperator> inFu = x -> y -> x*y; Replace line n2 with: IntStream newStream = stream.map(inFu.applyAsInt(10));
  • CReplace line n2 with: IntStream newStream = stream.map(inFu.applyAsInt(10));
  • DReplace line n2 with: IntStream newStream = stream.map(inFu.apply(10));

Community Discussion

No community discussion yet for this question.

Full 1Z0-809 Practice