how to traverse stack in java
Iterator value = stack.iterator();
// Displaying the values
// after iterating through the stack
System.out.println("The iterator values are: ");
while (value.hasNext()) {
System.out.println(value.next());
}
how to traverse stack in java
Iterator value = stack.iterator();
// Displaying the values
// after iterating through the stack
System.out.println("The iterator values are: ");
while (value.hasNext()) {
System.out.println(value.next());
}
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);
}
Copyright © 2021 Codeinu
Forgot your account's password or having trouble logging into your Account? Don't worry, we'll help you to get back your account. Enter your email address and we'll send you a recovery link to reset your password. If you are experiencing problems resetting your password contact us