Saturday, 10 May 2014

Stack : empty() : Tests whether stack is empty or not

public boolean empty()
Return true if this stack contains no items otherwise false.

import java.util.*;

class StackEmpty{
 public static void main(String args[]){
  Stack<Integer> myStack = new Stack<> ();
  
  System.out.print("Is myStack empty ");
  System.out.println(myStack.empty());
  
  /* Add Elements to myStack */
  System.out.println("\nAdding Elements to myStack");
  myStack.add(10);
  
  System.out.print("\nIs myStack empty ");
  System.out.println(myStack.empty());
 }
}

Output
Is myStack empty true

Adding Elements to myStack

Is myStack empty false


Prevoius                                                 Next                                                 Home

No comments:

Post a Comment