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.
3 points to say:
ArrayList:get(i)O(1), add at the end O(1).LinkedListmust walk to the node, O(n).- 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.