OK, I am confused. I thought the newer version of the for loop can work off a Collection as long as the Collection implements Iterable which I thought all Collections do now after
Java 5. I took this quote off a site, but have read this same thing elsewhere.
http://www.clanproductions.com/java5.html
On the up side, the new form can be applied to both arrays and collections seamlessly. In the expression for(<variable definition> : <expression>), the expression part can either be an instance of an array or an object that implements the Iterable interface. In Java 5 onwards, all java.util collection classes implement this interface, and so the 'new' form of the for loop can be used instead of an Iterator to iterate through any collection. This also gives developers a hook by making their classes Iterable, they can make them available for use within new forms of the for loop.
Here's an example using the java.util.LinkedHashSet.
Collection<Integer> scores = new LinkedHashSet<Integer>();
scores.add(99); // Use of auto boxing
scores.add(88);
scores.add(77);
for(Integer score : scores) {
System.out.println("This score is " + score);
}
Dosen't the loop get an Iterator to work from and therefore it is safe to remove an object from the Collection?