Skip to content
Sharp

Collections · interview question

What will happen if you try to access an index in an ArrayList that is out of bounds?

Multiple choiceMediumchapter-4-curatedpremiumcollectionslist-interface-and-arraylist
Choose one answer
Answer and explanation

Correct answer

A. It will throw an IndexOutOfBoundsException.

Why

Accessing an invalid index in an ArrayList results in an IndexOutOfBoundsException. This exception is specific to list operations, unlike ArrayIndexOutOfBoundsException, which is specific to arrays.

Test yourself on Collections

A free test with instant, explained results. No account needed.

Start free test
All Collections questions →