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

Given the code fragment:

Which statement can be inserted into line n1 to print 1,2; 1,10; 2,20;?

    Correct Answer: A

    To achieve the desired output, it is necessary to use an appropriate functional interface that can be passed to the forEach method of the Map interface. The forEach method expects a BiConsumer, which is a functional interface that accepts two input arguments and does not return a result. Therefore, using BiConsumer<Integer, Integer> with the appropriate implementation will print the key-value pairs as required. The correct statement to insert at line n1 is: BiConsumer<Integer,Integer> c = (i, j) -> {System.out.print(i + "," + j + "; ");}. This matches option A.

Discussion
pul26Option: A

Answer is A

sansay61Option: A

Function has an apply method. So its not b. Also biconsumer has <t,t> signature. So the answer is A

jduarteOption: A

Answer is A. Tested.

DarGrinOption: A

Answer is A. ForEach for Map Interface needs a BiConsumer, not BiFunction

steefaandOption: A

A is correct since forEach accepts Consumer or BiConsumer.

duydnOption: A

A is correct. Function use apply(), Consumer use accept(). Function<T, R> -> return R Consumer<T> -> void

shifasaleemOption: A

Answer is A

lchowenOption: A

forEach accepts Consumer or BiConsumer so B is definitely not correct. Answer is A

WilsonKKerllOption: A

Answer is A.