![]() |
VOOZH | about |
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.
[100, 200, 300, 400] Remove first element from the list: 400 [100, 200, 300]
public E removeLast()
Example 2: Here, the removeLast() is going to throw anNoSuchElementException if the list is empty.
Exception caught: java.util.NoSuchElementException