When I use an Iterator of Object I use a while loop (as written in every book learning Java, as Thinking in Java of Bruce Eckel):
I
The purpose of declaring the Iterator within the for loop is to minimize the scope of your variables, which is a good practice.
When you declare the Iterator outside of the loop, then the reference is still valid / alive after the loop completes. 99.99% of the time, you don't need to continue to use the Iterator once the loop completes, so such a style can lead to bugs like this:
//iterate over first collection
Iterator it1 = collection1.iterator();
while(it1.hasNext()) {
//blah blah
}
//iterate over second collection
Iterator it2 = collection2.iterator();
while(it1.hasNext()) {
//oops copy and paste error! it1 has no more elements at this point
}