// ReverseArgs.java // Applies a Stack to print command line arguments in reverse order // cmc, 7/27/06 import java.util.Stack; public class ReverseArgs { public static void main(String[] args) { // create a stack, specifically to hold String objects Stack stack = new Stack(); // push all the arguments on it, in forward order for (String s : args) stack.push(s); // now pop and print them - "last in, first out" order System.out.print("Reversed args:"); while ( !stack.isEmpty() ) System.out.printf(" %s", stack.pop()); System.out.println(); } }