迭代器使用测试Java

迭代器使用测试Java,第1张

迭代器使用测试Java
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

欢迎分享,转载请注明来源:内存溢出

原文地址:https://54852.com/zaji/5721954.html

(0)
打赏 微信扫一扫微信扫一扫 支付宝扫一扫支付宝扫一扫
上一篇 2022-12-18
下一篇2022-12-18

发表评论

登录后才能评论

评论列表(0条)

    保存