Skip to content

Instantly share code, notes, and snippets.

@learncsdesign
Last active May 1, 2022 03:30
Show Gist options
  • Save learncsdesign/dcb09dced537f4d861fe08587453d50a to your computer and use it in GitHub Desktop.
Save learncsdesign/dcb09dced537f4d861fe08587453d50a to your computer and use it in GitHub Desktop.
package com.learncsdesign;
import java.util.Stack;
public class MyStack {
public static void main(String[] args) {
Stack<String> animals = new Stack<>();
// LIFO
animals.push("Elephant");
animals.push("Lion");
animals.push("Tiger");
System.out.println("Size: " + animals.size());
System.out.println("Peek Element: " + animals.peek());
System.out.println("Size: " + animals.size());
System.out.println("Pop Element: " + animals.pop());
System.out.println("Size: " + animals.size());
while(!animals.isEmpty()) {
System.out.println(animals.pop());
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment