22.19 LinkedLists

LinkedLists

This note covers the concept of LinkedLists in Java, including implementation, operations, and use cases.

Topics

Examples

Singly Linked List

class Node {
    int value;
    Node next;

    Node(int value) {
        this.value = value;
        this.next = null;
    }
}

Node head = new Node(1);
head.next = new Node(2);
head.next.next = new Node(3);

Using Java's LinkedList Class

import java.util.LinkedList;

LinkedList<Integer> list = new LinkedList<>();
list.add(1);
list.add(2);
list.add(3);
System.out.println(list);

Tags

#java #linkedlist #datastructures #singlylinkedlist #doublylinkedlist