上述是接口的继承关系。

我们可以这么理解collection接口,就是一组数据,每个数据都称之为element(也就是元素);这些element可以是重复的,也可以不是重复的;可是有序的,也可以是无序的。

list接口可以理解为collection接口的一个特例,里面的元素是有序的,可是,依然可能是有重复的;但是因为是有序的,重复也就无关大雅。

而Set接口,就是没有重复的数据的collection,如果还需要排序,则可以考虑SortedSet接口。

Map接口,完全可以理解为,用key-value替代了单个的element。因此,有自己的接口体系。

一般情况下,java不会直接从collection继承,而是继承自其子接口,比如set,list等。

下面我们看看源代码:

public interface Collection<E> extends Iterable<E>

继承自Iterable接口,而Interable接口,完全就是collection框架用来替代enumation的。

int size();元素个数;

boolean isEmpty():没有元素,则返回值为true。

boolean contains(Object o);判断是否包含某个特定的object。
 Iterator<E> iterator();

Object[] toArray();把所有的元素换成一个数组,哈。

boolean add(E e);

* @param e element whose presence in this collection is to be ensured
     * @return <tt>true</tt> if this collection changed as a result of the
     *         call
     * @throws UnsupportedOperationException if the <tt>add</tt> operation
     *         is not supported by this collection
     * @throws ClassCastException if the class of the specified element
     *         prevents it from being added to this collection
     * @throws NullPointerException if the specified element is null and this
     *         collection does not permit null elements
     * @throws IllegalArgumentException if some property of the element
     *         prevents it from being added to this collection
     * @throws IllegalStateException if the element cannot be added at this
     *         time due to insertion restrictions

boolean remove(Object o);

* @param o element to be removed from this collection, if present
     * @return <tt>true</tt> if an element was removed as a result of this call
     * @throws ClassCastException if the type of the specified element
     *         is incompatible with this collection
     *         (<a href="#optional-restrictions">optional</a>)
     * @throws NullPointerException if the specified element is null and this
     *         collection does not permit null elements
     *         (<a href="#optional-restrictions">optional</a>)
     * @throws UnsupportedOperationException if the <tt>remove</tt> operation
     *         is not supported by this collection

boolean containsAll(Collection<?> c);

* @return <tt>true</tt> if this collection contains all of the elements
     *         in the specified collection
     * @throws ClassCastException if the types of one or more elements
     *         in the specified collection are incompatible with this
     *         collection
     *         (<a href="#optional-restrictions">optional</a>)
     * @throws NullPointerException if the specified collection contains one
     *         or more null elements and this collection does not permit null
     *         elements
     *         (<a href="#optional-restrictions">optional</a>),
     *         or if the specified collection is null.
     * @see    #contains(Object)

boolean addAll(Collection<? extends E> c);

void clear();
    boolean retainAll(Collection<?> c);
    boolean removeAll(Collection<?> c);
    boolean equals(Object o);
    int hashCode();

下面,来看一个图:

对于这个图的使用,首先,我们在最左面一列,找到合适的接口,然后,往左找,去找合适的类。

在学习前,我们首先明白以下内容:

1)所有的接口实现都是unsynchronized(http://www.cnblogs.com/devinzhang/archive/2011/12/14/2287675.html)

2)实行Iterator的fast-fail特性(http://www.cnblogs.com/xinglongbing/archive/2012/04/04/2432247.html)

3)允许拥有null元素。

4)The implementations rely on a concept of optional methods in interfaces. If an implementation doesn't
support an operation, such as adding or removing elements, the implementation throws an
UnsupportedOperationException when you call a method that hasn't been fully implemented.

java collections读书笔记(8)collection框架总览(1)的更多相关文章

  1. java collections读书笔记(9)collection框架总览(2)

    框架算法: 1)collection接口 add()  Adds an element to the collection.addAll()  Adds a collection of element ...

  2. java collections读书笔记(11) Lists

    继续这个系列,好久没学习了,懒惰呀. Set接口,实际上是collection 类别中最简单的一个接口,因为它并没有比Collection 接口增加任何的内容,相对而言,大家可能更喜欢List接口和它 ...

  3. java collections读书笔记(10) Set

    aaarticlea/png;base64,iVBORw0KGgoAAAANSUhEUgAAAVgAAADbCAIAAACnXR7VAAAgAElEQVR4nOx9d1hVV9Y3880zb2YmM3 ...

  4. Java并发读书笔记:线程安全与互斥同步

    目录 导致线程不安全的原因 什么是线程安全 不可变 绝对线程安全 相对线程安全 线程兼容 线程对立 互斥同步实现线程安全 synchronized内置锁 锁即对象 是否要释放锁 实现原理 啥是重进入? ...

  5. java effective 读书笔记

    java effective 读书笔记 []创建和销毁对象 静态工厂方法 就是“封装了底层 暴露出一个访问接口 ” 门面模式 多参数时 用构建器,就是用个内部类 再让内部类提供构造好的对象 枚举 si ...

  6. 深入理解Java虚拟机 -- 读书笔记(1):JVM运行时数据区域

    深入理解Java虚拟机 -- 读书笔记:JVM运行时数据区域 本文转载:http://blog.csdn.net/jubincn/article/details/8607790 本系列为<深入理 ...

  7. 单元测试之道Java版——读书笔记

    单元测试知道Java版读书笔记 首先我们必须要知道我们所写的代码,它的功能是什么,如果我们不了解代码的行为,那么也就无从测试. 我们测试的目的,是为了我们整个程序架构的稳定,代码其实就是欧文要实现功能 ...

  8. Java设置的读书笔记和集合框架Collection API

    一个.CollectionAPI 集合是一系列对象的聚集(Collection). 集合在程序设计中是一种重要的数据接口.Java中提供了有关集合的类库称为CollectionAPI. 集合实际上是用 ...

  9. 【java读书笔记】——Collection集合之六大接口(Collection、Set、List、Map、Iterator和Comparable)

    两个月之前准备软考时,简单的从理论上总结了最经常使用的数据结构和算法,比方:线性表,链表,图.在进行java开发时,jdk为我们提供了一系列对应的类来实现主要的数据结构.jdk所提供的容器API位于j ...

随机推荐

  1. ArcGIS Server发布服务,报错001270

    错误001270 这个问题一般是因为数据源文件太大导致. 解决办法:  对于001270的错误,官方帮助中给出了一些可能的原因并提供了相应的解决办法(http://resources.arcgis.c ...

  2. 一 mybatis快速入门

    什么是MyBatis MyBatis是支持普通SQL查询,存储过程和高级映射的优秀持久层框架. MyBatis消除了几乎所有的JDBC代码和参数的手工设置以及对结果集的检索. MyBatis可以使用简 ...

  3. springMVC框架下——通用接口之图片上传接口

    我所想要的图片上传接口是指服务器端在完成图片上传后,返回一个可访问的图片地址. spring mvc框架下图片上传非常简单,如下 @RequestMapping(value="/upload ...

  4. 【转】Unity3D中Layers和LayerMask解析

    http://blog.csdn.net/yupu56/article/details/50441151 Unity中是用int32来表示32个Layer层.int32表示二进制一共有32位(0-31 ...

  5. java正则表达式取括号里面的内容

    public static String changeCompName(String compName){ String NewCompName=""; //cm1230NHL6X ...

  6. taocode

    http://code.taobao.org/project/lang/list/Go/1/

  7. php--tp继承公共的控制器

  8. 超级管理员登录后如果连续XX分钟没有操作再次操作需要重新登录

    首先在设置session页面时 session_start(); session("name",$adminname); //加入session时间 time() session( ...

  9. job_chain

    JOB链:JOB之间的相互触发操作. 实验意图:有些JOB具有先后调用次序,比如先做一件事情,这件事情做完才能继续下一件事情,而第一个JOB如果自己挂掉的话,第二个JOB需要正常运行(默认是终止),这 ...

  10. Android性能优化典范(转)

    转载自oschina. 2015年伊始,Google发布了关于Android性能优化典范的专题, 一共16个短视频,每个3-5分钟,帮助开发者创建更快更优秀的Android App.课程专题不仅仅介绍 ...