java.util · java.base · since Java 1.2
LinkedList
public class LinkedList<E> extends AbstractSequentialList<E>
implements List<E>, Deque<E>, Cloneable, SerializableDoubly-linked list implementing both List and Deque. Almost always slower than ArrayList/ArrayDeque in practice — node allocations and pointer chasing dominate.
- get(i) walks the chain — O(n); iteration takes a cache miss per node
- Legitimate niche: cursor-based editing via ListIterator
Key methods
void addFirst(E) / addLast(E) | O(1) insertion at either end — the actual niche. |
E peekFirst() / E peekLast() | O(1) inspection without removal; null if empty. |
E pollFirst() / E pollLast() | O(1) null-returning removal from either end. |
void push(E) / E pop() | Stack aliases for addFirst()/removeFirst(). |
ListIterator<E> listIterator(int index) | Cursor with O(1) insert/remove at the cursor position — the one real edge over ArrayList. |