program 15

This commit is contained in:
2026-02-12 14:30:38 +05:30
parent 7cab60365e
commit 1a6f71bf5b
2 changed files with 22 additions and 0 deletions

BIN
Screenshots/program15.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 15 KiB

22
TestJavaCollection4.java Normal file
View File

@@ -0,0 +1,22 @@
// 15 write a java code to demonstrate stack
import java.util.*;
public class TestJavaCollection4 {
public static void main(String args[]){
Stack<String> stack = new Stack<>();
stack.push("Ayush");
stack.push("Garvit");
stack.push("Amit");
stack.push("Garima");
Iterator<String> itr = stack.iterator();
while(itr.hasNext()){
System.out.println(itr.next());
}
String topElement = stack.peek();
System.out.println("The top element of the stack is: " + topElement);
stack.pop();
System.out.println("After POP");
for(String element: stack){
System.out.println(element);
}
}
}