VOOZH about

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

⇱ LinkedList getLast() Method in Java - GeeksforGeeks


  • Courses
  • Tutorials
  • Interview Prep

LinkedList getLast() Method in Java

Last Updated : 11 Jul, 2025

In Java, the getLast() method in the LinkedList class is used to retrieve the last element of the list.

Example 1: Here, we use the getLast() method to retrieve the last element of the list.


Output
[Geeks, for, Geeks]
Geeks

Syntax of LinkedList getLast() Method

public E getLast()

Return type: It return the last element of the list.

👁 LinkedList getLast() Method work flow


Example 2: Here, the getLast() method throws an NoSuchElementException if the list is empty.


Output
The last element of the LinkedList is: 50
Error: java.util.NoSuchElementException
Comment