java collections读书笔记(8)collection框架总览(1)
上述是接口的继承关系。
我们可以这么理解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)的更多相关文章
- java collections读书笔记(9)collection框架总览(2)
框架算法: 1)collection接口 add() Adds an element to the collection.addAll() Adds a collection of element ...
- java collections读书笔记(11) Lists
继续这个系列,好久没学习了,懒惰呀. Set接口,实际上是collection 类别中最简单的一个接口,因为它并没有比Collection 接口增加任何的内容,相对而言,大家可能更喜欢List接口和它 ...
- java collections读书笔记(10) Set
aaarticlea/png;base64,iVBORw0KGgoAAAANSUhEUgAAAVgAAADbCAIAAACnXR7VAAAgAElEQVR4nOx9d1hVV9Y3880zb2YmM3 ...
- Java并发读书笔记:线程安全与互斥同步
目录 导致线程不安全的原因 什么是线程安全 不可变 绝对线程安全 相对线程安全 线程兼容 线程对立 互斥同步实现线程安全 synchronized内置锁 锁即对象 是否要释放锁 实现原理 啥是重进入? ...
- java effective 读书笔记
java effective 读书笔记 []创建和销毁对象 静态工厂方法 就是“封装了底层 暴露出一个访问接口 ” 门面模式 多参数时 用构建器,就是用个内部类 再让内部类提供构造好的对象 枚举 si ...
- 深入理解Java虚拟机 -- 读书笔记(1):JVM运行时数据区域
深入理解Java虚拟机 -- 读书笔记:JVM运行时数据区域 本文转载:http://blog.csdn.net/jubincn/article/details/8607790 本系列为<深入理 ...
- 单元测试之道Java版——读书笔记
单元测试知道Java版读书笔记 首先我们必须要知道我们所写的代码,它的功能是什么,如果我们不了解代码的行为,那么也就无从测试. 我们测试的目的,是为了我们整个程序架构的稳定,代码其实就是欧文要实现功能 ...
- Java设置的读书笔记和集合框架Collection API
一个.CollectionAPI 集合是一系列对象的聚集(Collection). 集合在程序设计中是一种重要的数据接口.Java中提供了有关集合的类库称为CollectionAPI. 集合实际上是用 ...
- 【java读书笔记】——Collection集合之六大接口(Collection、Set、List、Map、Iterator和Comparable)
两个月之前准备软考时,简单的从理论上总结了最经常使用的数据结构和算法,比方:线性表,链表,图.在进行java开发时,jdk为我们提供了一系列对应的类来实现主要的数据结构.jdk所提供的容器API位于j ...
随机推荐
- Progressive enhancement
https://en.wikipedia.org/wiki/Progressive_enhancement Progressive enhancement is a strategy for web ...
- wsdl 结构
WSDL文档可以分为两部分.分别是抽象部分和具体描述 部分. 抽象部分 抽象部分以独立于平台和语言的方式定义SOAP消息,它们并不包含任何随 机器或语言而变的元素.<types>.< ...
- js 键盘移动div、img对象
js 键盘移动div.img对象 <html> <script type="text/javascript"> var EXtype="" ...
- 蓝牙的L2CAP协议
1.概述 L2CAP能向上层提供面向连接的或者无连接的数据服务,拥有multiplexing capability and segmentation and reassembly operat ...
- AppleScript
一.资源 1.书本 2.ide: AppleSreipt Editor 3.界面辅助软件: UIBrowser 破解方法: a) ui browser -> show package conte ...
- cwe
- 【转】JSP中的9大隐藏对象
隐藏对象用在jsp表达式和脚本中,不能直接用在jsp声明中,因为这些隐藏对象是容器在jspservice方法中定义的,在这个方法中定义的变量不能在jsp声明中使用.可以通过参数方法将隐藏对象传递到js ...
- WIN 8.1使用常见问题及解决
WIN 8.1正式版64位(cn_windows_8_1_pro_vl_x64_dvd_2971907)使用问题及解决 一.IE11的输入框会变蓝: 如在百度中搜索时,搜索框和按钮均变成蓝色背景, ...
- 解决VS2010无法打开,提示无法找到atl100.dll的方法
这个问题是卸载VS2010一些组件造成的误删问题,且从网上下的atl100.dll通常与自己的VS2010不符 解决方法: 从路径:C:\Program Files\Microsoft Visual ...
- iOS8 推送注册方式改变的问题
不久之后iPhone 6/6 plus就会在国内如雨后春笋般遍地开花了.iOS 8早已现行一步,不过有的开发者也注意到了在iOS 8上推送通知的注册方式有所变化,报错提示为: 1 registerFo ...