遍历 List

List list =new ArrayList();
list.add("list4");
list.add("list2");
list.add("list3");
for (Iterator iterator=list.iterator();iterator.hasNext();){
    System.out.println(iterator.next());
}

遍历 Set

Set set=new HashSet();
set.add("set");
set.add("set2");
Iterator iterator1=set.iterator();
while(iterator1.hasNext()){
    System.out.println(iterator1.next());
}

遍历 Map

Map map=new HashMap();
map.put("a","map");
map.put("b","map2");
//先将map中的键存入Set,再使用迭代器遍历
Set集合
Set<String> set1=map.keySet();
Iterator iterator2=set1.iterator();
while (iterator2.hasNext()){
    System.out.println(map.get(iterator2.next()));
}