empty() Method

To check whether a stack is empty or not, we use the empty() method. For example,


\begin{lstlisting}
import java.util.Stack;
\par
class Main {
public static void...
...);
System.out.println(''Is the stack empty? '' + result);
}
}
\end{lstlisting}

Output


\begin{lstlisting}
Stack: [Dog, Horse, Cat]
Is the stack empty? false
\end{lstlisting}