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

Vikyath Ram
Vikyath Ram

A born rival

Updated on: 25-Feb-2020

87 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements