Given the code fragment: List<Integer> codes = Arrays.asList (10, 20); UnaryOperator<Double> uo = s -> s +10.0; codes.replaceAll(uo); codes.forEach(c -> System.out.println(c)); What is the result?
Click on the arrows to vote for the correct answer
A. B. C. D.C.
The given code fragment performs the following operations:
Arrays.asList
method and store it in the codes
variable.phpList<Integer> codes = Arrays.asList(10, 20);
UnaryOperator
instance uo
that adds 10.0 to a given Double value.kotlinUnaryOperator<Double> uo = s -> s + 10.0;
replaceAll
method of the List
interface to replace all the elements of the codes
list with the result of applying the uo
operator to each element of the list.scsscodes.replaceAll(uo);
After this step, the codes
list contains the elements [20.0, 30.0], because uo.apply(10)
returns 20.0
and uo.apply(20)
returns 30.0
.
forEach
method of the List
interface to print each element of the codes
list.rcodes.forEach(c -> System.out.println(c));
This will print:
20.0 30.0
Therefore, the correct answer is option A, which is "20.0 30.0". There are no compilation errors or runtime exceptions in the given code fragment.