Demo program for java.util.Stack
Pushing items on to the stack
There are 4 items in the stack.
Here is the stack, output method 1
item1
item2
item3
item4
Here is the stack, output method 2
item1
item2
item3
item4
Here is the stack, output method 2 but printed backwards
to show the traditional stack output
item4
item3
item2
item1
Here is the stack, output method 3, using toString()
[item1, item2, item3, item4]
Top of the stack is : item4
Popping all the items from the stack
item4
item3
item2
item1
Now there are 0 items in the stack.
Pushing items on to the stack
Here is the stack after addition of new items, unsorted
[item2, item1, item4, item7, item6, item5, item9]
Sorting items
Here is the stack after sorting
[item1, item2, item4, item5, item6, item7, item9]
Searching for Hello
Item NOT found
Searching for item6
Item found at position 4
Searching with alternate method which returns
1 based position from top of stack
Item found at position 3