星鸿
public class Test01 {
public static void main(String[] args) {
List list = new ArrayList();
list.add("aaa");
list.add("bbb");
list.add("ccc");
//通过迭代器遍历list
Iterator iter2 = list.iterator();
while(iter2.hasNext()) {
String str = (String) iter2.next();
System.out.println(str);
}
Set set = new HashSet();
set.add("gao1");
set.add("gao2");
set.add("gao3");
//通过迭代器遍历set
Iterator iter = set.iterator();
//for 和 while循环都可以
while(iter.hasNext()) {
String str = (String) iter.next();
System.out.println(str);
}
}
}