-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstack_eg.java
More file actions
36 lines (29 loc) · 1022 Bytes
/
stack_eg.java
File metadata and controls
36 lines (29 loc) · 1022 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
28
29
30
31
32
33
34
35
36
import java.util.*;
class stack_eg {
public static void main(String args[]) {
Stack stack1 = new Stack();
stack1.push("Ayan");
stack1.push("Amit");
stack1.push("Garima");
stack1.push("Garima");
System.out.println("Before popping any values: ");
Iterator itr = stack1.iterator();
while (itr.hasNext()) {
System.out.println(itr.next());
}
stack1.pop();
Iterator itr2 = stack1.iterator();
while (itr2.hasNext()) {
System.out.println(itr2.next());
}
System.out.println(stack1);
boolean b = stack1.empty();
System.out.println(b);
int pos = stack1.search("Ashish");
System.out.println("The element is at position: " + pos);
int pos1 = stack1.search("Ayan");
System.out.println("The element is at position: " + pos1);
stack1.removeAllElements();
System.out.println(stack1);
}
}