I need to iterate over the set of values for each iteration of for loop, but only for first iteration it works fine. Thereafter the itr.hasNext()
returns
You can only iterate an Iterator once.
If you need to "reset" it, and recreating the Iterator is expensive (such as reading from a file), you could copy the data into a temporary Collection (such as an ArrayList). But that requires enough memory to hold everything at once.
Another approach could be (depends on what your program does) to swap the order of loop nesting: Iterate over your iterator just once, and over your Person
s in the inner loop (since you already have all those in memory). Obviously, this processes things in a different order which may or may not be easy to accomodate for you.