Node Structure in LinkedList
What you'll learn: How LinkedList uses small Node objects, each holding an element and links to its neighbors, to form a chain of data.
The Building Block of LinkedList
While ArrayList stores elements in a single continuous array, LinkedList takes a completely different approach: it chains together individual Node objects. Each Node is a tiny container that holds three pieces of information.
Anatomy of a Node
Think of a Node like a train car in a freight train. Each car contains:
- Cargo (element): The actual data you're storing (a String, Integer, or any object)
- A link to the previous car (prev): A reference pointing backward to the Node before it
- A link to the next car (next): A reference pointing forward to the Node after it
In Java terms, the Node class looks conceptually like this:
class Node<E> {
E element; // The data being stored
Node<E> next; // Reference to the next node
Node<E> prev; // Reference to the previous node
}
Why Three References?
LinkedList in Java is doubly-linked, meaning you can traverse in both directions. If you're at any Node, you can move forward using next or backward using prev. The first Node's prev is null, and the last Node's next is null—these null references mark the ends of the chain.
This structure allows efficient insertion and removal anywhere in the list—you just rearrange the next and prev pointers without copying any elements.
Key Takeaway: A LinkedList Node holds your element plus two references (next and prev), creating a doubly-linked chain where each Node knows its neighbors, enabling bidirectional traversal.