program 15
This commit is contained in:
22
TestJavaCollection4.java
Normal file
22
TestJavaCollection4.java
Normal 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);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user