stack of integers java code example
Example 1: java stack
Stack<String> stack = new Stack<String>();
stack.push("Hello");
String top = stack.pop();
String peek = stack.peek();
Example 2: java stack methods
import java.util.Stack<E>;
Stack<Integer> myStack = new Stack<Integer>();
myStack.push(1);
myStack.pop();
myStack.peek();
myStack.empty();
Example 3: stack class in java
import java.util.Stack;
class Main {
public static void main(String[] args) {
Stack<String> animals= new Stack<>();
animals.push("Dog");
animals.push("Horse");
animals.pop();
animals.peek();
}
}