VOOZH about

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

⇱ LinkedList removeLast() Method in Java - GeeksforGeeks


  • Courses
  • Tutorials
  • Interview Prep

LinkedList removeLast() Method in Java

Last Updated : 11 Jul, 2025

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

Example 1: Here, we use the removeLast() method to remove and return the last element (tail) of the LinkedList.


Output
[100, 200, 300, 400]
Remove first element from the list: 400
[100, 200, 300]

Syntax of LinkedList removeLast() Method

public E removeLast()

  • Return Type: The last element (tail) that is removed from the list.
  • Exception: If the list is empty, calling removeLast() will throw a NoSuchElementException.

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


Output
Exception caught: java.util.NoSuchElementException
Comment