-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathCollectionStackQueue.java
More file actions
37 lines (30 loc) · 935 Bytes
/
CollectionStackQueue.java
File metadata and controls
37 lines (30 loc) · 935 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
37
import java.util.*;
public class CollectionStackQueue {
public static void main(String[] args) {
Stack<String> stack = new Stack<>();
stack.push("A");
stack.push("B");
stack.push("C");
stack.push("D");
System.out.println(stack);
String out = stack.pop();
System.out.println(out);
String last = stack.peek();
System.out.println(last);
System.out.println(stack);
Queue<String> queue = new LinkedList<>();
queue.offer("A");
queue.offer("B");
queue.offer("C");
queue.offer("D");
System.out.println(queue);
String outQ = queue.poll();
System.out.println(outQ);
String frontQ = queue.peek();
System.out.println(frontQ);
System.out.println(queue);
Set<String> set = new HashSet<>();
set.add(null);
System.out.println(set);
}
}