Choose the correct option based on this code segment:
List<Integer> ints = Arrays.asList(1, 2, 3, 4, 5);
ints.replaceAll(i -> i * i); // LINE
System.out.println(ints);
b)
the replaceAll()
method (added in Java 8 to the List interface) takes an UnaryOperator as the argument.
In this case, the unary operator squares the integer values.
hence, the program prints [1, 4, 9, 16, 25].
the underlying List object returned by Arrays.asList()
method can be modified using the replaceAll()
method and it does not result in throwing java.lang.UnsupportedOperationException.