Stack empty() Method in Java
The java.util.Stack.empty() method in Java is used to check whether a stack is empty or not. The method is of boolean type and returns true if the stack is empty else false.
Parameters: The method does not take any parameters.
Return Value: The method returns boolean true if the stack is empty else it returns false.
Below programs illustrate the working of java.util.Stack.empty() method:
The stack is: [Geeks, 4, Geeks, Welcomes, You] Is the stack empty? false Is the stack empty? true
The stack is: [8, 5, 9, 2, 4] Is the stack empty? false
Attention reader! Don’t stop learning now. Get hold of all the important Java Foundation and Collections concepts with the Fundamentals of Java and Java Collections Course at a student-friendly price and become industry ready. To complete your preparation from learning a language to DS Algo and many more, please refer Complete Interview Preparation Course.