--Start
JDK 5.0 provides an enhanced for loop statement that makes it easy for us to iterate over algebraic groups and collections. In fact, if any class implements the Iterable interface, it can be traversed using an enhanced for loop statement, and here's a simple example.
Import java.util.ArrayList;
Import Java.util.Iterator;
Import java.util.List;
public class Test {public
static void Main (string[] args) throws Exception {
Names Names = new Names ();
Names.add ("Zhang San");
Names.add ("Li Si");
for (String name:names) {
System.out.println (name);
}}} Class Names implements iterable<string> {
private list<string> Names = new arraylist<string> (); c14/>public void Add (String name) {
names.add (name);
}
Public iterator<string> iterator () {return
names.iterator ();
}
}
--- more See also:Java Fine Extract
-- statement: Reprint please indicate the source
--Last Updated on 2012-06-12
--written by Shangbo on 2012-06-12
--End