Multiple choice technology programming languages

You are planning to do an indexed search in a list of objects. Which of the two Java collections should you use?

  1. ArrayList

  2. LinkedList

  3. Set

  4. None

Reveal answer Fill a bubble to check yourself
A Correct answer
Explanation

ArrayList provides O(1) random access by index because it uses a contiguous array backing. LinkedList requires O(n) traversal from the head to reach an arbitrary index.

AI explanation

ArrayList is backed by a resizable array, so accessing an element by its index is a direct O(1) lookup — exactly what an indexed search needs. LinkedList would require walking the chain of nodes one by one to reach a given index (O(n)), and a Set doesn't support indexed access at all since it has no defined positional ordering.