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
No comments:
Post a Comment