QuestionQ43

Working with Selected Classes from the Java API

Given this code fragment:

Question Image

What is the output?

  • A [green, red, yellow, cyan]
  • B [green, blue, yellow, cyan]
  • C [green, red, cyan, yellow]
  • D An IndexOutOfBoundsException is thrown at runtime.
Explanation

Java List indexes are zero-based. Removing index 2 deletes red; inserting cyan at index 3 appends it after yellow, so the list prints as [green, blue, yellow, cyan].

Community Discussion

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