| 5 | |
| 6 | public class StackCollision { |
| 7 | public static void main(String[] args) { |
| 8 | onjava.Stack<String> stack = new onjava.Stack<>(); |
| 9 | for(String s : "My dog has fleas".split(" ")) |
| 10 | stack.push(s); |
| 11 | while(!stack.isEmpty()) |
| 12 | System.out.print(stack.pop() + " "); |
| 13 | System.out.println(); |
| 14 | java.util.Stack<String> stack2 = |
| 15 | new java.util.Stack<>(); |
| 16 | for(String s : "My dog has fleas".split(" ")) |
| 17 | stack2.push(s); |
| 18 | while(!stack2.empty()) |
| 19 | System.out.print(stack2.pop() + " "); |
| 20 | } |
| 21 | } |
| 22 | /* Output: |
| 23 | fleas has dog My |