first commit
This commit is contained in:
23
TestJavaCollection4.java
Normal file
23
TestJavaCollection4.java
Normal file
@@ -0,0 +1,23 @@
|
||||
// Write a java code to demo stack
|
||||
import java.util.*;
|
||||
public class TestJavaCollection4{
|
||||
public static void main(String args[]){
|
||||
Stack<String> stack = new Stack<String>();
|
||||
stack.push("Ayush");
|
||||
stack.push("Garvit");
|
||||
stack.push("Amit");
|
||||
stack.push("Ashish");
|
||||
stack.push("Garvit");
|
||||
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