diff --git a/Screenshots/program15.png b/Screenshots/program15.png new file mode 100644 index 0000000..9267995 Binary files /dev/null and b/Screenshots/program15.png differ diff --git a/TestJavaCollection4.java b/TestJavaCollection4.java new file mode 100644 index 0000000..f3e2366 --- /dev/null +++ b/TestJavaCollection4.java @@ -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 stack = new Stack<>(); + stack.push("Ayush"); + stack.push("Garvit"); + stack.push("Amit"); + stack.push("Garima"); + Iterator 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); + } + } +}