Linked List
A linked list is a linear data structure in which each element, called a node, stores its data and a reference (link) to the next node. Unlike an array, the nodes are not stored in contiguous memory, so the list can grow and shrink easily at runtime.
Inserting or removing a node only requires changing links, but reaching an element by position means walking the list from the head. Common variants are singly linked lists, doubly linked lists (with links to the previous node as well) and circular linked lists.
class Node {
int data;
Node next;
Node(int data) { this.data = data; }
}
Node head = new Node(10);
head.next = new Node(20);
head.next.next = new Node(30);
for (Node n = head; n != null; n = n.next) {
System.out.println(n.data); // 10, 20, 30
}