Exam 1z0-809 All QuestionsBrowse all questions from this exam
Question 2

Given:

IntStream stream = IntStream.of (1,2,3);

IntFunction inFu= x -> y -> x*y; //line n1

IntStream newStream = stream.map(inFu.apply(10)); //line n2 newStream.forEach(System.output::print);

Which modification enables the code fragment to compile?

    Correct Answer: B

    To ensure the code fragment compiles correctly, line n1 should be replaced with 'IntFunction<IntUnaryOperator> inFu = x -> y -> x * y;'. This defines 'inFu' as a function that takes an integer and returns an 'IntUnaryOperator'. The 'IntUnaryOperator' is a functional interface that takes an int and returns an int, which matches the expected behavior for the 'map' method in the IntStream class.

Discussion
YasinGaberOption: B

B, tested, but I think we need to change (System.output::print) to (System.out::print)

Svetleto13Option: B

Correct answer is B,tested.

WilsonKKerllOption: B

Correct answer is B.

asdfjhfgjuaDCVOption: B

B is the answer: import java.util.function.IntFunction; import java.util.function.IntUnaryOperator; import java.util.stream.IntStream; public class Main { public static void main(String[] args) { IntStream stream = IntStream.of(1, 2, 3); IntFunction<IntUnaryOperator> inFu = x -> y -> x * y; // Replace with option B IntStream newStream = stream.map(inFu.apply(10)); // line n2 newStream.forEach(System.out::print); } }

vietnamn1Option: B

The full of implement is IntFunction<IntUnaryOperator> inFu = new IntFunction<IntUnaryOperator>() { @Override public IntUnaryOperator apply(int value) { return new IntUnaryOperator() { @Override public int applyAsInt(int operand) { return value * operand; } }; } }; And it is a IntStream so map function will take IntUnaryOperation. So the inFu.apply(10) is correct return the IntUnaryOperation so the B is correct

Temilaw25Option: B

Answer is definitely B. This is an example of higher order function where the function interface returns another function.

r1muka5Option: B

Correct answer is B. The function.apply() expects IntFunction<IntUnaryOperator>