Specifications
Sun Services
Java™ Programming Language
Module 9, slide 36 of 37
Copyright 2005 Sun Microsystems, Inc. All Rights Reserved. Sun Services, Revision F
Enhanced for Loop
An enhanced for loop can look like this:
• Using iterators:
public void deleteAll(Collection<NameList> c){
for ( Iterator<NameList> i = c.iterator() ; i.hasNext() ; ){
NameList nl = i.next();
nl.deleteItem();
}
}
• Using enhanced for loop in collections:
public void deleteAll(Collection<NameList> c){
for ( NameList nl : c ){
nl.deleteItem();
}
}










