Collection&Iterable

发布时间 2023-11-09 19:43:52作者: anpeiyong

Collection

概述

The root interface in the <i>collection hierarchy</i>.
A collection represents a group of objects, known as its <i>elements</i>.
Some collections allow duplicate elements and others do not.
Some are ordered and others unordered.
The JDK does not provide any <i>direct</i> implementations of this interface: it provides implementations of more specific subinterfaces like <tt>Set</tt> and <tt>List</tt>.
This interface is typically used to pass collections around and manipulate them where maximum generality is desired.

集合的root接口;

collection代表一组对象,称对象为元素;

jdk没有提供直接的collection的实现,提供了子接口:Set、List;

public interface Collection<E> extends Iterable<E> {

    Iterator<E> iterator();

}

  

Iterable

概述

Implementing this interface allows an object to be the target of the "for-each loop" statement.

实现Iterable,允许一个对象进行遍历;

 

public interface Iterable<T> {

    Iterator<T> iterator();

}