Java Stack.empty()

Syntax

Stack.empty() has the following syntax.

public boolean empty()

Example

In the following code shows how to use Stack.empty() method.


//ww w .  jav a 2 s .  c  o  m


import java.util.Stack;

public class Main {
   public static void main(String args[]) {
      
      Stack st = new Stack();
      
      // populating stack
      st.push("Java");
      st.push("Source");
      st.push("from java2s.com");
      
      
      System.out.println("Is stack empty: "+st.empty());
   }    
}

The code above generates the following result.