Creating a Stack

In order to create a stack, we must import the java.util.Stack package first. Once we import the package, here is how we can create a stack in Java.


\begin{lstlisting}
Stack<Type> stacks = new Stack<>();
\end{lstlisting}

Here, Type indicates the stack's type. For example,


\begin{lstlisting}
// Create Integer type stack
Stack<Integer> stacks = new Stac...
... Create String type stack
Stack<String> stacks = new Stack<>();
\end{lstlisting}