QuestionQ141

Working with Selected Classes from the Java API

Given this code fragment:

Question Image

What result is produced?

  • A [Robb, Rick, Bran]
  • B [Robb, Rick]
  • C [Robb, Bran, Rick, Bran]
  • D An exception is thrown at runtime.
Explanation

For a List<String>, remove(Object) removes the first occurrence of the specified value and returns true when that value was present. Removing the first "Bran" leaves Robb, Rick, and the second Bran. Removing the absent value "Jon" has no effect and does not throw an exception.

Community Discussion

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