-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathStackCollision.java
More file actions
37 lines (32 loc) · 1.08 KB
/
StackCollision.java
File metadata and controls
37 lines (32 loc) · 1.08 KB
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
package holding;
/**
* RUN:
* javac holding/StackCollision.java && java holding.StackCollision
* OUTPUT:
* stack: holding.Stack [fleas, has, dog, My]
* fleas has dog My
* stack2: java.util.Stack [My, dog, has, fleas]
* fleas has dog My
*/
public class StackCollision {
public static void main(String[] args) {
Stack<String> stack = new Stack<String>();
for (String s : "My dog has fleas".split(" ")) {
stack.push(s);
}
System.out.println("stack: " + stack.getClass().getName()+" "+stack);
while ( ! stack.empty()) {
System.out.print(stack.pop() + " ");
}
System.out.println();
java.util.Stack<String> stack2 = new java.util.Stack<String>();
for (String s : "My dog has fleas".split(" ")) {
stack2.push(s);
}
System.out.println("stack2: " + stack2.getClass().getName()+ " "+stack2);
while ( ! stack2.empty()) {
System.out.print(stack2.pop() + " ");
}
System.out.println();
}
}