import java.util.ArrayList;
import java.util.Collection;
import java.util.Iterator;
public class 迭代器 {
public static void main(String[] args) {
// TODO 自动生成的方法存根
Collection<String> aCollection = new ArrayList<String>();
aCollection.add("hello");
aCollection.add("world");
aCollection.add("java");
Iterator<String> it = aCollection.iterator();
it.next();
System.out.println(it.next());
System.out.println(it.next());
ArrayList<String> arrayList = new ArrayList<>();
arrayList.add("hello");
arrayList.add("world");
arrayList.add("java");
Iterator<String> it2 = arrayList.iterator();
System.out.println(it2.next());
System.out.println(it2.next());
System.out.println(it2.next());
}
}
输出结果
world
java
hello
world
java