上述是接口的继承关系。

我们可以这么理解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. iOS中利用CoreTelephony获取用户当前网络状态(判断2G,3G,4G)

    前言: 在项目开发当中,往往需要利用网络.而用户的网络环境也需要我们开发者去注意,根据不同的网络状态作相应的优化,以提升用户体验. 但通常我们只会判断用户是在WIFI还是移动数据,而实际上,移动数据也 ...

  2. GetLogicalProcessorInformation(XP3才支持)和GetLogicalProcessorInformationEx(WIN7才支持)

    https://msdn.microsoft.com/en-us/library/windows/desktop/ms683194(v=vs.85).aspx 例子执行结果如下: https://ms ...

  3. 改变当前shell工作目录

    执行脚本时候,只是在当前的shell下开了一个子进程,切换目录的操作只对该进程中相关后续指令有效,但改变不了父进程的目录. 解决方法: 法一: 用 source a.sh就行了. 法二: [fedor ...

  4. [LeetCode]题解(python):040-Combination Sum II

    题目来源 https://leetcode.com/problems/combination-sum-ii/ Given a collection of candidate numbers (C) a ...

  5. Maven集成Sonar

    Sonar对maven提供了简单可配的支持,要做的事情很简单--在maven/conf下settings.xml <profiles></profiles>标签之间添加如下内容 ...

  6. jquery效果

    //隐藏显示 <!doctype html> <html lang="en"> <head> <meta charset="UT ...

  7. extjs form.load()加载服务端数据

    formPanel.getForm().load({ url: 'getApproveRefundInf?refundIdDetail=${refundIdDetail}', waitMsg: '请稍 ...

  8. 获取dom元素的宽度和高度

    一.获取css的大小 1.第一种通过内联样式 var box = document.getElementById('box'); var w = box.style.width; var h = bo ...

  9. 配置文件后面的rc的由来

    配置文件后面的rc的由来 配置文件比较正规的叫法是:运行控制文件  run control Linux就这个范儿 4.5.3 配置文件 配置文件比较文绉绉的称呼是“运行控制文件”,存放与具体程序相关的 ...

  10. 30天,App创业从0到1【7.12西安站】

    活动概况 时间:2015年07月12日13:30-16:30 地点:汇天使咖啡(高新路36号智空间二楼) 主办:APICloud.UPYUN.万紫网络 网址:www.apicloud.com 费用:免 ...