Given the code fragment:
Which statement can be inserted into line n1 to print 1,2; 1,10; 2,20;?
Given the code fragment:
Which statement can be inserted into line n1 to print 1,2; 1,10; 2,20;?
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.
Answer is A
Function has an apply method. So its not b. Also biconsumer has <t,t> signature. So the answer is A
Answer is A. Tested.
Answer is A. ForEach for Map Interface needs a BiConsumer, not BiFunction
A is correct since forEach accepts Consumer or BiConsumer.
A is correct. Function use apply(), Consumer use accept(). Function<T, R> -> return R Consumer<T> -> void
Answer is A
forEach accepts Consumer or BiConsumer so B is definitely not correct. Answer is A
Answer is A.