![]() |
VOOZH | about |
In Java, the push() method of the LinkedList class is used to push an element at the starting(top) of the stack represented by LinkedList. This is similar to the addFirst() method of LinkedList. This method simply inserts the element at the first position or top of the LinkedList.
public void push(Object element);
Parameters: This method accepts one parameter element of object type and represents the element to be inserted. The type "Object" should be of the same Stack represented by the LinkedList.
Example: Here, we use the push() method to push elements at the beginning of the LinkedListof Integers.
Linked List is : [10, 20, 30]
Note: We can also use the push() method with LinkedList of Strings, Objects etc.