What Does the Method Empty Do in Java



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
Updated on: 2020-02-25T10:00:29+05:30

122 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements