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();这句的意思是什么
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();这句的意思是什么
这样就提供了统一的方法,遍历数据。给编程者带来方便。
这种做法也被 称作为 Iterator 设计模式。
Iterator i=c.iterator();
while(i.hasNext())
{
Object o = i.next();
}
具体可以翻API 和源码。