package java_test;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Iterator;
/**
* iterator 的使用
* 迭代器是集合取元素的统一接口
* @author Administrator
*
*/
public class Iterator_use {
public static void main(String[] args) {
Collection coll = new ArrayList();
coll.add("abc");
coll.add("def");
coll.add("gh");
//--------------------
Iterator it = coll.iterator();//**********************
while(it.hasNext()){
System.out.println(it.next());
}
//-------------------------
for(Iterator it2 = coll.iterator();it2.hasNext();){
System.out.println(it2.next());
}
}
}
import java.util.ArrayList;
import java.util.Collection;
import java.util.Iterator;
/**
* iterator 的使用
* 迭代器是集合取元素的统一接口
* @author Administrator
*
*/
public class Iterator_use {
public static void main(String[] args) {
Collection coll = new ArrayList();
coll.add("abc");
coll.add("def");
coll.add("gh");
//--------------------
Iterator it = coll.iterator();//**********************
while(it.hasNext()){
System.out.println(it.next());
}
//-------------------------
for(Iterator it2 = coll.iterator();it2.hasNext();){
System.out.println(it2.next());
}
}
}