iterate a stack in java code example
Example: how to traverse a stack in java
Just get the Iterator via iterator():
Stack<YourObject> stack = ...
Iterator<YourObject> iter = stack.iterator();
while (iter.hasNext()){
System.out.println(iter.next());
}
Or alternatively, if you just want to print them all use the enhanced-for loop:
for(YourObject obj : stack)
{
System.out.println(obj);
}