首页 > 其他 > 详细

JDK源码阅读(三) Collection<T>接口,Iterable<T>接口

时间:2015-10-03 13:10:30      阅读:493      评论:0      收藏:0      [点我收藏+]
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();
}

 技术分享 

技术分享

JDK源码阅读(三) Collection<T>接口,Iterable<T>接口

原文:http://www.cnblogs.com/wuxinliulei/p/4853243.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!