![]() |
VOOZH | about |
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.
[Geeks, for, Geeks] Geeks
public E getLast()
Return type: It return the last element of the list.
Example 2: Here, the getLast() method throws an NoSuchElementException if the list is empty.
The last element of the LinkedList is: 50 Error: java.util.NoSuchElementException