-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathStackCollection.java
More file actions
25 lines (20 loc) · 825 Bytes
/
Copy pathStackCollection.java
File metadata and controls
25 lines (20 loc) · 825 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
package LeetcodePractice;
import java.util.Stack;
public class StackCollection {
public static void main(String[] args) {
Stack<String> animals = new Stack<>();
animals.push("lion");
animals.push("Elephant");
animals.push("Fox");
animals.push("Tiger");
animals.push("Dog");
animals.push("Cheetah");
animals.push("Horse");
System.out.println("My Animals stack is " + animals);
//for checking which element in stack is on top we use peek function
System.out.println("topmost animal is " + animals.peek());
//for removing we use pop function and it always remove topmost
System.out.println("Remove topmost " + animals.pop());
System.out.println("final update stack is " + animals);
}
}