![]() |
VOOZH | about |
In Java, the pop() method of the LinkedList class is used to remove and return the top element from the stack represented by the LinkedList. The method simply pops out an element present at the top of the stack. This method is similar to the removeFirst method in LinkedList.
Example 1: Here, we use the pop() method to remove and return the first element (head) of the LinkedList.
100 [200, 300, 400]
public E pop()
Example 2: Here, the pop() is going to throw an NoSuchElementException if the list is empty.
Exception caught: java.util.NoSuchElementException