Stack empty() in Java

empty(): This method is available in java.util.Stack class of Java.

Syntax:

boolean java.util.Stack.empty()

This method tests if this stack is empty.

Parameters: NA

Returns: true if and only if this stack contains no items; false otherwise.

Exceptions: NA

Approach

Java

import java.util.Stack;

public class Stackempty {
    public static void main(String[] args) {

        Stack<Integer> st = new Stack<>();

        st.push(1);
        st.push(18);
        st.push(29);
        st.push(8);
        System.out.println(st.empty());

    }
}

Output:

false


No comments:

Post a Comment