上述是接口的继承关系。

我们可以这么理解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. PHP中数组合并的两种方法及区别介绍

    PHP数组合并两种方法及区别 如果是关联数组,如下: 复制代码代码如下: $a = array( 'where' => 'uid=1', 'order' => 'uid', ); $b = ...

  2. mysql之触发器trigger 详解

    为了梦想,努力奋斗! 追求卓越,成功就会在不经意间追上你 mysql之触发器trigger 触发器(trigger):监视某种情况,并触发某种操作. 触发器创建语法四要素:1.监视地点(table)  ...

  3. 2016/4/21 关于jquery复习

    jQuert AJAX [1]jQuery load()方法 :是AJAX方法, 从服务器加载数据,并把数据放入被选元素中 语法: $(selector).load(URL,data,callback ...

  4. mysql 存储过程 php版本

    <?php /** * PHP操作Mysql存储过程示例 * * @author flyer0126 * @date 2011-12-23 * */ //配置数据库连接信息 $hostname ...

  5. win7 创建软链接方式

    mklink  目标文件  源文件(需要被软链的文件) Win7中的软链接详解(mklink命令) Post by 铁木箱子 in 技术杂谈 on 2011-05-24 13:13. 点评一下 评论 ...

  6. 【转】设计模式(三)建造者模式Builder(创建型)

    (http://blog.csdn.net/hguisu/article/details/7518060) 1. 概述 在软件开发的过程中,当遇到一个"复杂的对象"的创建工作,该对 ...

  7. Python之 continue继续循环和多重循环

    Python之 continue继续循环 在循环过程中,可以用break退出当前循环,还可以用continue跳过后续循环代码,继续下一次循环. 假设我们已经写好了利用for循环计算平均分的代码: L ...

  8. javascript的alert()的消息框不弹出或者弹出信息有误

    有时不知道什么,有时javascript的alert()的消息框不弹出或者弹出信息有误,代码是这么写的: //提示信息 public static void alert(TemplateControl ...

  9. Google物联网操作系统协同框架Weave深度解析

    1.       Google Weave框架 在2015年的Google I/O大会上,负责Android业务的桑达.皮查伊(SundarPichai)宣布了Google最新的物联网战略.这包括一个 ...

  10. Cygwin + CMake 测试

    https://www.cygwin.com/ apt-get for cygwin? wget rawgit.com/transcode-open/apt-cyg/master/apt-cyg in ...