What does the method empty() do in java?

Java 8Object Oriented ProgrammingProgramming

The empty() method is used to test if this stack is or not.

Example

import java.util.*;
public class StackDemo {
   public static void main(String args[]) {
   
      Stack st = new Stack();
      st.push("Java");
      st.push("Source");
      st.push("code");
      System.out.println("Is stack empty: "+st.empty());
   }
}

Output

Is stack empty: false
raja
Published on 08-Feb-2018 13:22:22
Advertisements