SteelReed

Search

Search posts, questions…

Collections & DSAQuestion 3 / 25

Junior

How do ArrayList and LinkedList differ, and when do you use each?

Short answer

ArrayList is a contiguous array, get(i) is O(1). LinkedList is linked nodes, get(i) is O(n). In practice you almost always pick ArrayList.

YesNoNeed a listAdd/removeat both ends?ArrayDequeArrayListContiguous arrayfast reads

3 points to say:

  1. ArrayList: get(i) O(1), add at the end O(1).
  2. LinkedList must walk to the node, O(n).
  3. For a double-ended queue use ArrayDeque.

Keep reading the deep dive

Create a free account to read the full explanation and follow-up questions, mark questions as studied and review them on a schedule.