Say I'm iterating over a set in java, e.g.
Iterator<_someObject_> it = _someObject_.iterator();
well, first I want to go through every object in the set and make a change to each object I visit. So I use:
while(it.hasNext()) {
_someObject_ = it.next();
_someObject_.add3(); //made up method
}
Now that I've done this, I decide I want to iterate through the entire set from start to finish once more to carry out another method on them, given that I've just made changes to each element through my first iteration.
Can I just use
while(it.hasNext())
again?
I thought maybe the iterator has a pointer so once it's reached the last element on the first run through, if I call while(it.hasNext()) again, the pointer would still be at the end of the set, meaning my second while loop would be pointless.