什么是迭代器?
Iterator iterator():迭代器,集合的专用遍历方式
迭代器的方法
public static void main(String[] args) {
// 首先创建集合对象
Collection c = new ArrayList();
// 创建并添加元素
c.add("貂蝉");
c.add("王昭君");
c.add("大乔");
// Iterator iterator():迭代器,集合的专用遍历方式 创建迭代器
Iterator it = c.iterator();
//利用while循环遍历出来
while (it.hasNext()) {
String s = (String) it.next();
System.out.println(s);
}