同三楼解~ 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(); }
java.util Interface Collection<E>All Superinterfaces: Iterable<E> All Known Subinterfaces 以上是API中的说明,可知Collection继承了Iterator接口
其实 这个叫做 Iterator 模式。 设计模式的一种。 主要是方便 遍历 List 和 Set ~~ 这样的话,我不需要知道 Collection中的是List or Set 直接 iterater 就好了~~~屏蔽了细节。
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();
}
Interface Collection<E>All Superinterfaces:
Iterable<E>
All Known Subinterfaces
以上是API中的说明,可知Collection继承了Iterator接口
设计模式的一种。
主要是方便 遍历 List 和 Set ~~
这样的话,我不需要知道 Collection中的是List or Set
直接 iterater 就好了~~~屏蔽了细节。