19 lines
500 B
Java
19 lines
500 B
Java
// collections/StackTest2.java
|
|
// (c)2021 MindView LLC: see Copyright.txt
|
|
// We make no guarantees that this code is fit for any purpose.
|
|
// Visit http://OnJava8.com for more book information.
|
|
import onjava.*;
|
|
|
|
public class StackTest2 {
|
|
public static void main(String[] args) {
|
|
Stack<String> stack = new Stack<>();
|
|
for(String s : "My dog has fleas".split(" "))
|
|
stack.push(s);
|
|
while(!stack.isEmpty())
|
|
System.out.print(stack.pop() + " ");
|
|
}
|
|
}
|
|
/* Output:
|
|
fleas has dog My
|
|
*/
|