Check out example codes for "java stack methods". It will help you in understanding the concepts better.

Code Example 1

// construct with non-primative elements only!
Stack<String> stack = new Stack<String>();

// to add a value to the top of the stack:

// to return and remove a value from the top:
String top = stack.pop();

// to return a value without removing it:
String peek = stack.peek();

Code Example 2

import java.util.Stack<E>;
Stack<Integer> myStack = new Stack<Integer>();
myStack.empty(); // True if stack is empty

Learn ReactJs, React Native from