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

158 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements