LinkedList in Java
LinkedList, also from java.util, stores elements as a chain of individually-linked nodes rather than one contiguous array — each node holds a value plus a reference to the next (and previous, since Java's is doubly-linked) node in the chain. That structural difference flips ArrayList's performance trade-offs: inserting or removing at the front or middle is fast, since it only means relinking a couple of neighboring nodes, but reaching an arbitrary index requires walking the chain node by node from one end.
LinkedList also implements the Deque interface, giving it efficient addFirst, addLast, removeFirst, and removeLast operations — which is why it's a common choice specifically when a program needs a queue or a stack rather than general-purpose indexed access.
Node-based structure
Each element lives in its own node, holding a value and links to its neighboring nodes, rather than sitting in one shared array.
Fast insertion and removal at known positions
Adding or removing right after a node the program already has a reference to only means relinking a couple of pointers.
Slow indexed access
get(index) has to walk the chain from the nearest end, one node at a time, until it reaches that position.
Doubly-linked in Java
Each node links both forward and backward, which is why LinkedList can walk efficiently in either direction.
Deque operations
addFirst, addLast, removeFirst, and removeLast are all fast, making LinkedList a natural fit for stack or queue behavior.
import java.util.LinkedList; public class LinkedListDemo { public static void main(String[] args) { LinkedList<String> queue = new LinkedList<>(); queue.addLast("first"); queue.addLast("second"); queue.addFirst("zeroth"); System.out.println(queue); System.out.println("Removed: " + queue.removeFirst()); }}Every element carries the extra overhead of its node links, and reaching an arbitrary index means walking the chain — there's no shortcut the way direct array indexing provides.
Recommended resourcesAffiliate links · may earn us a commission
Recommended for learners
Practice what you learned
Re-implement each visualized algorithm in Java yourself — building beats watching.