此系列文章放在了我的专栏里, 欢迎查看
https://blog.csdn.net/column/details/24187.html
相关衔接
从源码看Android常用的数据结构 ( SDK23版本 ) ( 一 , 总述 )
从源码看Android常用的数据结构 ( SDK23版本 ) ( 二, List篇 )
从源码看Android常用的数据结构 ( SDK23版本 ) ( 三 , Queue篇)
从源码看Android常用的数据结构 ( SDK23版本 ) ( 四, Set篇 )
从源码看Android常用的数据结构 ( SDK23版本 ) ( 五, Map篇 )
从源码看Android常用的数据结构 ( SDK23版本 ) ( 六, ConcurrentHashMap )
从源码看Android常用的数据结构 ( 七, SDK28下的HashMap )
Github里有一份Android使用到的小技术, 欢迎查看:
https://github.com/YouCii/LearnApp
总览
常用的数据结构都是从 Collection 和 Map 接口发散的.
这两个接口在 java sdk 和 android sdk 里各有一份, android sdk 的实现类如下:
这里面的重复类也都是 java sdk 和 android sdk各有一份, android sdk 对 java sdk 进行了删减与扩展, 这篇文章只整理 android sdk 中的.
其中 Collection 的实现类里包括了平时常见的 List, Queue, Set 等.
List
List 接口的官方注释
A {
@code List} is a collection which maintains an ordering for its elements. Every
element in the {
@code List} has an index. Each element can thus be accessed by its
index, with the first index being zero. Normally, {
@code List}s allow duplicate
elements, as compared to Sets, where elements have to be unique.
List是一个保持其元素顺序的集合. 每个List中的元素具有index索引, 每个元素都可以通过从0开始的index访问.
通常, List允许元素重复, 而Sets则要求元素必须唯一.
实现 List 接口中日常使用比较多的类有以下几个:
ArrayList, LinkedList(也同时实现了Queue), Vector, Stack, CopyOnWriteArrayList.
具体分析写在第二篇里 从源码看Android常用的数据结构 ( SDK23版本 ) ( 二, List篇 )
Queue
A collection designed for holding elements prior to processing.
Besides basic {
@link java.util.Collection Collection} operations,
queues provide additional insertion, extraction, and inspection
operations. Each of these methods exists in two forms: one throws
an exception if the operation fails, the other returns a special
value (either <tt>null</tt> or <tt>false</tt>, depending on the
operation). The latter form of the insert operation is designed
specifically for use with capacity-restricted <tt>Queue</tt>
implementations; in most implementations, insert operations cannot
fail.
是一种用于在处理前持有elements的集合。除了基本的Collection操作之外,
Queue提供了额外的插入、提取和检查操作。每个方法都有两种形式:一种
是操作失败时抛出异常, 另一种是返回model或者根据操作类型返回null以及false。
后一种插入操作形式是专门设计于Queue有容量限制的实现类, 因为在大多数实现类里,
插入操作不允许失败。
实现 Queue 接口的主要实现类有以下几个:
LinkedList(也同时实现了List), ArrayBlockingQueue, LinkedBlockingQueue, SynchronousQueue, DelayQueue, Deque相关
具体分析请看 从源码看Android常用的数据结构 ( SDK23版本 ) ( 三 , Queue篇)
Set
A {
@code Set} is a data structure which does not allow duplicate elements.
Set是一种不允许元素重复的数据结构.
主要实现类有: ArraySet, HashSet/LinkedHashSet, TreeSet, CopyOnWriteArraySet
具体请见 从源码看Android常用的数据结构 ( SDK23版本 ) ( 四, Set篇 )
Map
A {
@code Map} is a data structure consisting of a set of keys and values
in which each key is mapped to a single value. The class of the objects
used as keys is d