1Iterator value = stack.iterator();
2// Displaying the values
3// after iterating through the stack
4System.out.println("The iterator values are: ");
5while (value.hasNext()) {
6 System.out.println(value.next());
7}
1Just get the Iterator via iterator():
2
3Stack<YourObject> stack = ...
4
5Iterator<YourObject> iter = stack.iterator();
6
7while (iter.hasNext()){
8 System.out.println(iter.next());
9}
10Or alternatively, if you just want to print them all use the enhanced-for loop:
11
12for(YourObject obj : stack)
13{
14 System.out.println(obj);
15}