Java Reference
In-Depth Information
for (Iterator<Attr> iter = obj.iterator();
iter.hasNext();
/* no update expression */)
{
Attr attr = iter.next();
System.out.println(attr);
}
As before the advantage of the enhanced
for
is a simple, syntactic con-
struct for accessing the elements you are iterating through. But you can-
not use the iterator's
remove
method to alter the collection, nor can you
iterate through multiple collections at the same time. If you need these
capabilities you must use the basic
for
statement and an explicit iterat-
or.