Saturday 10 May 2014

Vector : push (E item) : Push Element to the stack

public E push(E item)
Pushes an item onto the top of this stack. Return the item pushed on to the stack.

import java.util.*;

class StackPush{
 public static void main(String args[]){
  Stack<Integer> myStack = new Stack<> ();
  
  /* Add Elements to myStack */
  myStack.push(10);
  myStack.push(20);
  myStack.push(30);
  
  System.out.println("Elements in myStack are");
  System.out.println(myStack);
 }
}

Output
Elements in myStack are
[10, 20, 30]


Prevoius                                                 Next                                                 Home

No comments:

Post a Comment