bc0026c3e1
Plus many new examples in "streams" chapter.
16 lines
333 B
Java
16 lines
333 B
Java
// containers/StackTest.java
|
|
import onjava.*;
|
|
|
|
public class StackTest {
|
|
public static void main(String[] args) {
|
|
Stack<String> stack = new Stack<>();
|
|
for(String s : "My dog has fleas".split(" "))
|
|
stack.push(s);
|
|
while(!stack.empty())
|
|
System.out.print(stack.pop() + " ");
|
|
}
|
|
}
|
|
/* Output:
|
|
fleas has dog My
|
|
*/
|