exam questions

Exam 1z0-809 All Questions

View all questions & answers for the 1z0-809 exam

Exam 1z0-809 topic 1 question 2 discussion

Actual exam question from Oracle's 1z0-809
Question #: 2
Topic #: 1
[All 1z0-809 Questions]

Given:
IntStream stream = IntStream.of (1,2,3);
IntFunction<Integer> 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?

  • A. Replace line n1 with: IntFunction<UnaryOperator> inFu = x -> y -> x*y;
  • B. Replace line n1 with: IntFunction<IntUnaryOperator> inFu = x -> y -> x*y;
  • C. Replace line n1 with: BiFunction<IntUnaryOperator> inFu = x -> y -> x*y;
  • D. Replace line n2 with: IntStream newStream = stream.map(inFu.applyAsInt (10));
Show Suggested Answer Hide Answer
Suggested Answer: B 🗳️

Comments

Chosen Answer:
This is a voting comment (?). It is better to Upvote an existing comment if you don't have anything to add.
Switch to a voting comment New
MPignaProTech
1 month, 4 weeks ago
Selected Answer: B
B is correct
upvoted 1 times
...
asdfjhfgjuaDCV
10 months, 1 week ago
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); } }
upvoted 1 times
...
vietnamn1
1 year ago
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
upvoted 1 times
...
Temilaw25
1 year, 7 months ago
Answer is definitely B. This is an example of higher order function where the function interface returns another function.
upvoted 1 times
...
r1muka5
1 year, 10 months ago
Correct answer is B. The function.apply() expects IntFunction<IntUnaryOperator>
upvoted 1 times
...
WilsonKKerll
2 years, 10 months ago
Correct answer is B.
upvoted 2 times
...
YasinGaber
2 years, 11 months ago
B, tested, but I think we need to change (System.output::print) to (System.out::print)
upvoted 3 times
...
Svetleto13
3 years, 8 months ago
Correct answer is B,tested.
upvoted 3 times
...
Community vote distribution
A (35%)
C (25%)
B (20%)
Other
Most Voted
A voting comment increases the vote count for the chosen answer by one.

Upvoting a comment with a selected answer will also increase the vote count towards that answer by one. So if you see a comment that you already agree with, you can upvote it instead of posting a new comment.

SaveCancel
Loading ...
exam
Someone Bought Contributor Access for:
SY0-701
London, 1 minute ago