// collections/StackTest.java // (c)2020 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 java.util.*; public class StackTest { public static void main(String[] args) { Deque stack = new ArrayDeque<>(); for(String s : "My dog has fleas".split(" ")) stack.push(s); while(!stack.isEmpty()) System.out.print(stack.pop() + " "); } } /* Output: fleas has dog My */