为什么说要实现Collection就必须实现iterator()?

解决方案 »

  1.   

    Collection接口定义了iterator函数
      

  2.   

    实现Collection类的所有子类都有iterator方法,返回一个实现了Iterator接口的对象
      

  3.   

    Collection是个接口,你的类继承这个接口必须实现这个接口里面的所有函数,其中就包括Iterator<E> iterator()这个函数
      

  4.   

    迭代器接口是集合接口的父接口,超级接口,实现类实现Collection时就必须实现Iterator接口
      

  5.   

    iterator是最顶端的,collecton继承了iterator
      

  6.   

    同三楼解~
    public interface Collection<E> extends Iterable<E>public interface Iterable<T> {    /**
         * Returns an iterator over a set of elements of type T.
         * 
         * @return an Iterator.
         */
        Iterator<T> iterator();
    }
      

  7.   

    java.util 
    Interface Collection<E>All Superinterfaces: 
    Iterable<E> 
    All Known Subinterfaces
    以上是API中的说明,可知Collection继承了Iterator接口
      

  8.   

    其实 这个叫做 Iterator 模式。
    设计模式的一种。
    主要是方便 遍历 List 和 Set ~~ 
    这样的话,我不需要知道 Collection中的是List or Set  
    直接 iterater 就好了~~~屏蔽了细节。