how to reserve a stack java code example
Example 1: java stack
// construct with non-primative elements only!
Stack<String> stack = new Stack<String>();
// to add a value to the top of the stack:
stack.push("Hello");
// to return and remove a value from the top:
String top = stack.pop();
// to return a value without removing it:
String peek = stack.peek();
Example 2: add element to stack java
Stack<String> stack = new Stack<String>();
stack.add("Geeks");