-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathStackBasic.java
More file actions
27 lines (24 loc) · 846 Bytes
/
StackBasic.java
File metadata and controls
27 lines (24 loc) · 846 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
26
27
// Program: Demonstration of Java Stack Class
// Topic: Stack Data Structure (java.util.Stack)
// Description: Shows basic operations on a stack using Java’s built-in `Stack` class.
// Pushes and pops string elements ("Dog", "Horse", "Cat") to demonstrate LIFO behavior.
// Prints the stack before and after a pop operation to show how elements are added and removed.
package stack;
import java.util.Stack;
/**
*
* @author Samim
*/
public class StackBasic
{
public static void main(String args[])
{
Stack<String> animals=new Stack<>();
animals.push("Dog");
animals.push("Horse");
animals.push("Cat");
System.out.println("Stack :"+animals);
animals.pop();
System.out.println("Stack After Pop :"+animals);
}
}