What is the difference between ArrayList and LinkedList in Java?
Point
ArrayList
LinkedList
Inside
Resizable array
Doubly linked nodes
Get by index
Fast, O(1)
Slow, O(n)
Add at the end
Fast (usually)
Fast
Add or remove at the start
Slow, O(n)
Fast, O(1)
Memory
Less
More (each node has two links)
Also a Deque
No
Yes
In practice ArrayList is the better choice for almost all cases, because of its simple memory layout. For a queue or a stack use ArrayDeque. See Java HashSet and LinkedList.