QuestionQ70

Working with Selected Classes from the Java API

Given this code fragment:

Question Image

What is the outcome?

  • A Compilation fails.
  • B The program compiles, but it prints nothing.
  • C HiHowAreYou removed
  • D An UnsupportedOperationException is thrown at runtime.
Explanation

ArrayList is mutable, and removeIf removes elements for which its predicate returns true, returning true when at least one element was removed. The predicate prints each string before testing it, producing HiHowAreYou; only Hi has length at most two, so the conditional then prints removed. Oracle ArrayList documentation

Learn more

Community Discussion

No comments yet. Be the first to start the discussion!