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