1z0-809 Exam QuestionsBrowse all questions from this exam

1z0-809 Exam - Question 128


Given the code fragment:

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

Show Answer
Correct Answer: AB

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

9 comments
Sign in to comment
pul26Option: A
Dec 9, 2020

Answer is A

sansay61Option: A
Dec 22, 2020

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

jduarteOption: A
Apr 8, 2021

Answer is A. Tested.

WilsonKKerllOption: A
Apr 1, 2022

Answer is A.

lchowenOption: A
Sep 21, 2022

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

shifasaleemOption: A
Nov 30, 2022

Answer is A

duydnOption: A
Sep 22, 2023

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

steefaandOption: A
Feb 7, 2024

A is correct since forEach accepts Consumer or BiConsumer.

DarGrinOption: A
May 31, 2024

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