Stack is a very useful data structure. Java comes with java.util.Stack class that can be used to get the required results.
Stack stack = new Stack();
stack.push("Australia");
stack.push("Austria");
System.out.println(stack.pop());
System.out.println(stack.pop());
Output: