import java.util.ArrayList;
import java.util.Iterator;
public class TestIte {
public static void main(String[] args) {
ArrayList al = new ArrayList();
for(int i = 0; i < 5; i++) {
al.add(new Integer(i));
// System.out.println(al);
}
Iterator e = al.iterator();
while(e.hasNext())
{
System.out.println((Integer)e.next());
}
}
}
注意while循环,不能用if,if只能输出一个0.
用foreach可以简写:
for(Iterator e = al.iterator(); e.hasNext(); ) {
System.out.println(e.next());
}
import java.util.Iterator;
public class TestIte {
public static void main(String[] args) {
ArrayList al = new ArrayList();
for(int i = 0; i < 5; i++) {
al.add(new Integer(i));
// System.out.println(al);
}
Iterator e = al.iterator();
while(e.hasNext())
{
System.out.println((Integer)e.next());
}
}
}
注意while循环,不能用if,if只能输出一个0.
用foreach可以简写:
for(Iterator e = al.iterator(); e.hasNext(); ) {
System.out.println(e.next());
}