Java OCA OCP Practice Question 1623

Question

What is the result of the following?

List<String> list = new ArrayList<>();
list.add("Austin");
list.add("Boston");
list.add("San Francisco");
 
list.removeIf(a -> a.length() > 10);
System.out.println(list.size());
  • A. 1
  • B. 2
  • C. 3
  • D. None of the above


B.

Note

On a stream, the filter() method only keeps values matching the lambda.

The removeIf() does the reverse on a Collection and keeps the elements that do not match.

In this case, that is Austin and Boston so Option B is correct.




PreviousNext

Related