VOOZH about

URL: https://www.geeksforgeeks.org/java/linkedlist-removefirst-method-in-java/

⇱ LinkedList removeFirst() Method in Java - GeeksforGeeks


  • Courses
  • Tutorials
  • Interview Prep

LinkedList removeFirst() Method in Java

Last Updated : 11 Jul, 2025

In Java, the removeFirst() method of the LinkedList class is used to remove and return the first element of the list.

Example 1: Here, we use the removeFirst() method to remove the first element (head) of the LinkedList of Integers.


Output
[100, 200, 300, 400]
Removed First element: 100
[200, 300, 400]

Syntax of LinkedList remove() Method

public E removeFirst()

  • Return Type: The method returns the first element (head) that is removed from the list.
  • Exception: If the list is empty, calling removeFirst() will throw a NoSuchElementException.

Example 2: Here, the removeFirst() is going to throw anNoSuchElementException if the list is empty.


Output
Exception caught: java.util.NoSuchElementException
Comment