
import java.util.ArrayList;
import java.util.Collection;
import java.util.Iterator;
public class 迭代器 {
public static void main(String[] args) {
// TODO 自动生成的方法存根
Collection aCollection = new ArrayList();
aCollection.add("hello");
aCollection.add("world");
aCollection.add("java");
Iterator it = aCollection.iterator();
it.next();
System.out.println(it.next());
System.out.println(it.next());
ArrayList arrayList = new ArrayList<>();
arrayList.add("hello");
arrayList.add("world");
arrayList.add("java");
Iterator it2 = arrayList.iterator();
System.out.println(it2.next());
System.out.println(it2.next());
System.out.println(it2.next());
}
}
输出结果
world java hello world java
欢迎分享,转载请注明来源:内存溢出
微信扫一扫
支付宝扫一扫
评论列表(0条)