使用迭代遍历集合

public class GH {

    public static void main(String[] args) {

  //使用多态的方式来创建集合
            Collection co=new ArrayList<String>();

    //分别赋五个值
            co.add("张");
            co.add("张1");
            co.add("张2");
            co.add("张3");
            co.add("张4");

  //使用迭代的方式来遍历添加的内容
            Iterator it=co.iterator();

    //用while判断一下
            while (it.hasNext()){


                String s=(String)it.next();


                System.out.println(s);
            }
            
}

}

原文地址:https://www.cnblogs.com/hph1728390/p/10570707.html