Java OCA OCP Practice Question 3105

Question

Choose the correct option based on this code segment:

List<Integer> ints = Arrays.asList(1, 2, 3, 4, 5);
ints.removeIf(i -> (i % 2 ==0)); // LINE
System.out.println(ints);
  • a) this code segment prints: [1, 3, 5]
  • b) this code segment prints: [2, 4]
  • c) this code segment prints: [1, 2, 3, 4, 5]
  • d) this code segment throws java.lang.UnsupportedOperationException
  • e) this code segment results in a compiler error in the line marked with the comment LINE


d)

Note

the underlying List object returned by Arrays.asList() method is a fixed-size list and hence we cannot remove elements from that list.

hence calling removeIf() method on this list results in throwing an UnsupportedOperationException.




PreviousNext

Related