Machine-translated by Google. Questions are authored in English.
Top

Discussion

What happens when an ArrayList exceeds its capacity - which of the following is true?

  • A.It links a second array to the first, so no copying is needed.
  • B.It refuses the addition and returns false from add.
  • C.It allocates a larger array and copies the elements across, transparently to the caller.
  • D.It throws IndexOutOfBoundsException, since the capacity is fixed at construction.

Answer: C

Capacity is an internal detail: when the backing array is full the list allocates a bigger one and copies, so add remains amortised constant time. Giving a sensible initial capacity avoids repeated copying, but the list is never limited by it.

No comment is present. Be the first to comment.
Loading…

Post your comment

Please log in or register to post a comment.