Collection c=new HashSet();
  c.add(new Name("f1","l1"));
  c.add(new Name("f2","l2"));
  c.add(new Name("f3","l3"));
  Iterator i=c.iterator();
 while(i.hasNext())
{
 ...
 }
java Iterator i=c.iterator();这句的意思是什么

解决方案 »

  1.   

    获取他的迭代器,可以通过迭代器hasNext判断集和里是否有元素,next反回集合中元素。
      

  2.   

    查下Java的API 查找Iterator 你就明白一切了
      

  3.   

    由于不同的collection有不有同的遍历操作,为了统一接口。添加每个实现 collection接口的类都要实现Iterator。
    这样就提供了统一的方法,遍历数据。给编程者带来方便。
    这种做法也被 称作为 Iterator 设计模式。
    Iterator i=c.iterator();
    while(i.hasNext())
    {
     Object o = i.next();
     }
    具体可以翻API 和源码。