package java.util;
public interface Collection<E> extends Iterable<E> {
//返回该集合中元素的数量
int size();
//判断该集合中元素是否为空 size() == 0
boolean isEmpty();
boolean contains(Object o);
Iterator<E> iterator();
Object[] toArray();
<T> T[] toArray(T[] a);
boolean add(E e);
boolean remove(Object o);
boolean containsAll(Collection<?> c);
boolean addAll(Collection<? extends E> c);
boolean removeAll(Collection<?> c);
boolean retainAll(Collection<?> c);
void clear();
boolean equals(Object o);
int hashCode();
}
上面是Collection<T>接口,该接口扩展了Iterator<T>接口
Collection接口是处理对象集合的根接口,接口提供了在集合中添加和删除元素的基本操作。
Collection接口提供的toArray()方法返回一个表示集合的数组。
package java.lang;
import java.util.Iterator;
/** Implementing this interface allows an object to be the target of
* the "foreach" statement.
* @since 1.5
*/
public interface Iterable<T> {
/**
* Returns an iterator over a set of elements of type T.
*
* @return an Iterator.
*/
Iterator<T> iterator();
}