0
点赞
收藏
分享

微信扫一扫

迭代器使用测试Java

westfallon 2022-02-05 阅读 55
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
举报

相关推荐

0 条评论