LinkedList (java.util.LinkedList) is Java's doubly linked list. It implements both List and Deque, so it can act as a list, a queue or a stack, and adding or removing at either end takes constant time. Its weakness is random access: get(index) walks the nodes, so it costs O(n).
Despite its reputation, LinkedList is rarely the fastest choice on modern hardware. ArrayList and ArrayDeque usually beat it because their elements sit next to each other in memory. Knowing when LinkedList still makes sense is the real answer to its significance.
Each element lives in a separate node object holding the item, a reference to the previous node and a reference to the next node. The list keeps references to the first and last node. Inserting at the head or tail only relinks a few references, and nothing is copied or resized.
On a typical 64-bit JVM with compressed references, a node costs about 24 bytes on top of the element itself, compared with 4 bytes per slot in an ArrayList. So LinkedList uses more memory per element, not less. The original claim that it is more memory efficient for changing sizes is incorrect.
| Operation | LinkedList | ArrayList | ArrayDeque |
|---|---|---|---|
get(i) / set(i) | O(n) | O(1) | not supported |
| Add or remove at the head | O(1) | O(n) | O(1) |
| Add or remove at the tail | O(1) | O(1) amortised | O(1) |
| Insert in the middle by index | O(n) to find, O(1) to link | O(n) shift | not supported |
Insert at an Iterator position | O(1) | O(n) | not supported |
| Memory per element | high (node object) | low | low |
Allows null | yes | yes | no |
Inserting "in the middle" is only cheap when you already hold an iterator at that position. Finding the position by index costs O(n), which cancels the advantage in most programs.
Since Java 21, List is a SequencedCollection, so getFirst(), getLast(), addFirst(), removeLast() and reversed() work on every list, including ArrayList. LinkedList already had most of them.
The one place the linked structure pays off is iterator-based removal, because the iterator already holds the node:
Calling numbers.remove(x) inside an enhanced for loop instead throws ConcurrentModificationException. For simple filters, numbers.removeIf(n -> n % 2 == 0) is shorter and clearer.
Reasonable uses:
null elements or need List methods on the same object. Otherwise ArrayDeque is faster and lighter.ListIterator while scanning.Prefer something else when:
ArrayList.ArrayDeque.LinkedList is not synchronised. Use ConcurrentLinkedQueue, LinkedBlockingQueue or Collections.synchronizedList.TreeSet, PriorityQueue or HashMap.Only at the ends or at an iterator position you already hold. For insertion by index, finding the node is O(n) and poor cache locality often makes ArrayList as fast or faster even in the middle.
No. Concurrent modification without external locking can corrupt the list or throw ConcurrentModificationException.
Yes to both.
ArrayDeque in almost every case. It has no per-node allocation and is faster. Choose LinkedList only if you need null elements.
LinkedList is a doubly linked list that doubles as a Deque, giving O(1) work at both ends and during iterator-based edits, but O(n) indexed access and a high memory cost per element. Default to ArrayList for lists and ArrayDeque for queues and stacks, and keep LinkedList for the narrow cases that benefit from its structure.