import java.util.Stack;
class Main {
public static void main(String[] args) {
Stack<String> animals= new Stack<>();
// Add elements to Stack
animals.push("Dog");
animals.push("Horse");
animals.push("Cat");
System.out.println("Stack: " + animals);
}
}
// Java Code to illustrate push() Method
import java.util.*;
// Main class
public class StackDemo {
// Main driver method
public static void main(String args[])
{
// Creating an empty Stack
Stack& lt;
String& gt;
STACK = new Stack& lt;
String& gt;
();
// Adding elements into the stack
// using push() method
STACK.push(" Welcome & quot;);
STACK.push(" To & quot;);
STACK.push(" Geeks & quot;);
STACK.push(" For & quot;);
STACK.push(" Geeks & quot;);
// Displaying the Stack
System.out.println(" Initial Stack
: "
+ STACK);
// Pushing elements into the stack
STACK.push(" Hello & quot;);
STACK.push(" World & quot;);
// Displaying the final Stack
System.out.println(" Final Stack
: "
+ STACK);
}
}