collection接口解析

来源:互联网 发布:淘宝下单后商品下架了 编辑:程序博客网 时间:2024/06/06 07:28

collection接口解析

public interface Collection<E> extends Iterable<E> 

继承Iterable<E>接口
Iterable<E>接口只有一个方法

  Iterator<T> iterator();

实现一个迭代器
迭代器中有3个方法

  boolean hasNext();    E next();    void remove();

方法

    int size();//计算集合大小    boolean isEmpty();//判断集合是否为空    boolean contains(Object o);//集合是否包含此对象    Iterator<E> iterator();//生成一个迭代器    Object[] toArray(); //将集合转化为 Object的数组    <T> T[] toArray(T[] a);//将集合转化为任意类型的数组    boolean add(E e);//添加元素    boolean remove(Object o);//通过对象移除元素    boolean containsAll(Collection<?> c);//判断集合是否包含集合C内所有元素    boolean addAll(Collection<? extends E> c);//像集合中添加集合C    boolean removeAll(Collection<?> c);//从集合中移除集合C包含的所有元素    boolean retainAll(Collection<?> c);//从集合中移除集合C不包含的所有元素    void clear();//清空集合    boolean equals(Object o);//判断对象是否相等    int hashCode();//产生hashCode的方法}
原创粉丝点击