public
void push(E e)
Pushes
an element onto the stack represented by this list. This method is
equivalent to addFirst.
import java.util.*; class LinkedListPush{ public static void main(String args[]){ LinkedList<Integer> myList; myList = new LinkedList<> (); System.out.print("Push 10 to myList "); myList.push(10); System.out.println("Elements in myList are"); System.out.println(myList); System.out.print("Push 20 to myList "); myList.push(20); System.out.println("Elements in myList are"); System.out.println(myList); } }
Output
Push 10 to myList Elements in myList are [10] Push 20 to myList Elements in myList are [20, 10]
No comments:
Post a Comment