stacking java code example
Example 1: java stack methods
import java.util.Stack<E>;
Stack<Integer> myStack = new Stack<Integer>();
myStack.push(1);
myStack.pop();
myStack.peek();
myStack.empty();
Example 2: java stack pop
package com.tutorialspoint;
import java.util.*;
public class StackDemo {
public static void main(String args[]) {
Stack st = new Stack();
st.push("Java");
st.push("Source");
st.push("code");
System.out.println("Removed object is: "+st.pop());
System.out.println("Elements after remove: "+st);
}
}