Example of Java Reset Iterator
import java.util.ArrayList;
import java.util.Iterator;
import java.util.ListIterator;
public class reset {
public static void main(String[] args) {
char alphabet = 'a';
ArrayList list = new ArrayList();
while (alphabet != 'z') {
list.add(alphabet++);
}
ListIterator it = list.listIterator();
while (it.hasNext()) {
System.out.print(it.next() + " ");
}
System.out.println();
while (it.hasNext()) {
System.out.print("* " + it.next() + " ");// it doesnot work
}
while (it.hasPrevious()) {
it.previous();
}
while (it.hasNext()) {
System.out.print("." + it.next() + " ");// it works
}
}
}
Output
a b c d e f g h i j k l m n o p q r s t u v w x y .a .b .c .d .e .f .g .h .i .j .k .l .m .n .o .p .q .r .s .t .u .v .w .x .y