Deletion from the beginning in a Linked List in Java

Java Program for Deletion from the beginning in a Linked List

In this article you will learn how Deletion from the Beginning in a Linked List in Java works, how to perform it step by step, and how to implement it using different approaches. This operation is very important for understanding how linked list pointers work and is commonly asked in coding interviews.

Deletion from the beginning in a linked list is one of the simplest and most frequently used operations in data structures.

Deletion-from-the-beginning-in-a-Linked-List-in-Java

Deletion from the beginning in a Linked List in Java

What is Deletion from the Beginning in a Linked List?

In a singly linked list, each node holds data and a pointer to the next node.
Deletion from the beginning simply means removing the first node (head node) and making the next node the new head.

Example:

Before deletion: 10 → 20 → 30 → 40
After deletion: 20 → 30 → 40

Only the head pointer changes. No other nodes move.

Learning Deletion from the Beginning in a Linked List in Java helps you understand:

  • Node removal
  • Pointer updates
  • Memory release (Java Garbage Collector handles it)
  • Handling edge cases (empty list, single node list)
Singly-Linked-List-Deletion-in-Java-at-Start
Singly-Linked-List-Deletion-in-Java-at-Start

Methods for Deletion from the beginning in a Linked List in Java

Here on this page we will discuss 2 different methods for Deletion from the beginning in a Linked List in Java​:

  1. Method 1: Simple Pointer Update (Iterative)
  2. Method 2: Using a Wrapper or LinkedList Class Structure
Linked-List-Deletion-at-the-Start-in-Java

Methods for Deletion from the beginning in a Linked List in Java

Method 1: Simple Pointer Update (Iterative)

Algorithm:

  1. Let head be the starting node of the list.
  2. If head is null, return null (list is empty).
  3. Store head.next in a temporary pointer newHead.
  4. Disconnect the old head by setting head.next = null.
  5. Return newHead as the updated head.

Java Code:

Run
class DeleteBegin {

    static class Node {
        int data;
        Node next;
        Node(int data) { this.data = data; }
    }

    public static Node deleteFromBeginning(Node head) {
        if (head == null) return null;

        Node newHead = head.next;
        head.next = null; // disconnect old head
        return newHead;
    }

    public static void printList(Node head) {
        while (head != null) {
            System.out.print(head.data + " ");
            head = head.next;
        }
        System.out.println();
    }

    public static void main(String[] args) {
        Node head = new Node(10);
        head.next = new Node(20);
        head.next.next = new Node(30);

        System.out.println("Before deletion:");
        printList(head);

        head = deleteFromBeginning(head);

        System.out.println("After deletion:");
        printList(head);
    }
}

Input:

10 20 30

Output:

20 30

Methods for Deletion from the beginning in a Linked List

Method 2: Deletion Using Linked List Class Wrapper

Algorithm:

  1. Create a LinkedList class with a head pointer.

  2. If head is null, do nothing.

  3. Assign head = head.next.

  4. Old head is automatically removed by garbage collection.

Java Code:

Run
class LinkedListDeletion {

    static class Node {
        int data;
        Node next;
        Node(int data) { this.data = data; }
    }

    static class LinkedList {
        Node head;

        public void deleteFromBeginning() {
            if (head == null) return;
            head = head.next;
        }

        public void add(int data) {
            Node newNode = new Node(data);
            newNode.next = head;
            head = newNode;
        }

        public void printList() {
            Node temp = head;
            while (temp != null) {
                System.out.print(temp.data + " ");
                temp = temp.next;
            }
            System.out.println();
        }
    }

    public static void main(String[] args) {
        LinkedList list = new LinkedList();
        list.add(30);
        list.add(20);
        list.add(10);

        System.out.println("Before deletion:");
        list.printList();

        list.deleteFromBeginning();

        System.out.println("After deletion:");
        list.printList();
    }
}

Input:

10 20 30  (head at 10)

Output:

20 30

Comparison between Methods for Deletion from the beginning

MethodTime ComplexitySpace Complexity
Simple Pointer UpdateO(1)O(1)
Using LinkedList Wrapper ClassO(1)O(1)

In this article, you learned everything about Deletion from the Beginning in a Linked List in Java, including algorithms, code examples

and complexities. Since it requires only a single pointer update, it is one of the fastest and simplest linked list operations. Understanding it helps you build a strong foundation in linked list manipulation and prepares you for advanced operations.

FAQ's related to Deletion from the beginning in a Linked List in Java

Answer:

It is the process of removing the head node and pointing the head to the next node in the list.

Answer:

You update the head pointer to head.next and disconnect the old head.

Answer:

Yes, it takes constant time O(1) because only one pointer is changed.

Answer:

Yes, Java’s garbage collector releases memory of the removed node automatically.

Answer:

Yes, by repeatedly applying Deletion from the Beginning operation.

Get over 200+ course One Subscription

Courses like AI/ML, Cloud Computing, Ethical Hacking, C, C++, Java, Python, DSA (All Languages), Competitive Coding (All Languages), TCS, Infosys, Wipro, Amazon, DBMS, SQL and others

Checkout list of all the video courses in PrepInsta Prime Subscription

Checkout list of all the video courses in PrepInsta Prime Subscription

Singly Linked List

  • Introduction to Linked List in Data Structure
    Click Here
  • Linked List in –
    C | C++ | Java
  • Singly Linked List in –
    C | C++ | Java
  • Insertion in singly Linked List –
    C | C++ | Java
  • Insertion at beginning in singly Linked List  –
    C | C++Java
  • Insertion at nth position in singly Linked List  –
    C | C++Java
  • Insertion at end in singly Linked List  –
    C | C++Java
  • Deletion in singly Linked List  –
    C | C++Java
  • Deletion from beginning in singly linked list :
    C | C++ | Java
  • Deletion from nth position in singly linked list :
    C | C++ | Java
  • Deletion from end in singly linked list :
    C | C++ | Java
  • Linked List Insertion and Deletion –
    C | C++Java
  • Reverse a linked list without changing links between nodes (Data reverse only) –
    C | C++Java
  • Reverse a linked list by changing links between nodes –
    C | C++Java
  • Print reverse of a linked list without actually reversing –
    C |C++Java
  • Print reverse of a linked list without actually reversing –
    C |C++Java
  • Insertion in the middle Singly Linked List –
    C | C++Java
  • Insertion in a Sorted Linked List –
    C | C++Java
  • Delete alternate nodes of a Linked List –
    C | C++Java
  • Find middle of the linked list –
    C | C++Java
  • Reverse a linked list in groups of given size –
    C | C++Java
  • Find kth node from end of the linked list –
    C | C++Java
  • Append the last n nodes of a linked list to the beginning of the list –
    C | C++Java
  • Check whether linked list is palindrome or not –
    C | C++Java
  • Fold a Linked List –
    C | C++Java
  • Insert at given Position –
    C | C++Java
  • Deletion at given Position –
    C | C++Java

Singly Linked List

  • Introduction to Linked List in Data Structure
  • Linked List in – C | C++ | Java
  • Singly Linked List in – C | C++ | Java
  • Insertion in singly Linked List – C | C++ | Java
    • Insertion at beginning in singly Linked List  – C | C++Java
    • Insertion at nth position in singly Linked List  – C | C++Java
    • Insertion at end in singly Linked List  – C | C++Java
  • Deletion in singly Linked List  – C | C++Java
    • Deletion from beginning in singly linked list : C | C++ | Java
    • Deletion from nth position in singly linked list : C | C++ | Java
    • Deletion from end in singly linked list : C | C++ | Java
  • Reverse a linked list without changing links between nodes (Data reverse only) – C | C++Java
  • Linked List Insertion and Deletion – C | C++Java
  • Reverse a linked list by changing links between nodes – C | C++Java
  • Linked List insertion in the middle – C | C++Java
  • Print reverse of a linked list without actually reversing – C |C++ | Java
  • Search an element in a linked list – C | C++Java
  • Insertion in a Sorted Linked List – C | C++Java
  • Delete alternate nodes of a Linked List – C | C++Java
  • Find middle of the linked list – C | C++Java
  • Reverse a linked list in groups of given size – C | C++Java
  • Find kth node from end of the linked list – C | C++Java
  • Append the last n nodes of a linked list to the beginning of the list – C | C++Java
  • Check whether linked list is palindrome or not – C | C++Java
  • Fold a Linked List – C | C++Java
  • Insert at a given position – C | C++Java
  • Delete at a given position – C | C++Java