Reference
Stack (abstract data type) - wikipedia
Next-to-bottom line:
If you push some objects onto a stack, the last one that you pushed is the first one that will be popped.
Therefore, if you push stuff on a stack and then pop the objects and print each one as it is popped, you will print them in the reverse order.
Now... A big intuitive leap to get to the
Bottom line:
Create a second stack. When you print each object that you pop off of the first stack, push it onto the second stack.
Now, what happens when you pop the objects off of the second stack and print each one as it is popped?
Try it! Use pencil and paper; no computer needed just yet.
Next: How to do it in Java? Reference
Java Stack Class
I mean, your code for instantiating a Stack <String> object and pushing some Strings looks pretty good for starters (assuming your cell phone put '*' where you intended spaces).
So...
For the first part of the program, to print the Strings in reverse order:
Declare an object of type Stack<String>
Push some Strings onto the stack, using the Stack.push() method
Make a loop using the Stack.empty() method as loop control:
While the stack is not empty
BEGIN LOOP
Use the Stack.pop() method to pop the top value from the stack:
Set a String equal to the value popped from the stack.
Print the popped String's value and do whatever else you need to do
END LOOP
Now, implement that and take a look at what it prints. The Strings in reverse order, right?
So, now do the second part.
Cheers!
Z