Java集合源码学习(1)_架构
来源:互联网 发布:非农数据图 编辑:程序博客网 时间:2024/06/05 09:34
Java集合,学习了一下源码;代码的架构值得学习理解;
本文仅整理了java集合的常用的类的结构,具体的接口和集合实现会在后面的文章中一边学习一边记录;
1:Collection接口
集合的根接口,继承了接口Iterable<E>;代表了多个元素的集合,该集合是否有序、是否允许重复值,都是在具体的子类中定义的;
java doc中有这样一句话:Bags or multisets (unordered collections that may contain duplicate elements) should implement this interface directly.
接口中定义了集合通用的方法:add 、addAll、remove、removeAll、clear、contains、containsAll、isEmpty、size、toArray、iterator等方法
任何一个实现都可以返回一个Iterator来遍历集合内所有元素
2:List接口
继承接口Collection一个有序(插入顺序)允许重复的集合,可以根据index来查询;
增加了根据位置信息操作集合的若干操作,add(index,E)、get(index)、indexof(index)、remove(index)、set(index,E)等方法;
还有一个获取ListIterator的方法,ListIterator可以增加或者替换当前位置的元素,可以向前遍历集合
2.1:ArrayList
2.2:LinkedList
2.3:Vector
2.4:CopyOnWriteArrayList
3:Set接口
继承接口Collection一个不允许重复的集合,判断标准为equals方法,是否允许null要看具体的实现;
没有增加特别的方法
3.1SortedSet接口
有序的Set,排序方法为compareTo或者提供的Comparator;提供了几个方法:first()、last()、headSet()、tailSet()
3.1.1TreeSet
3.2HashSet
3.2.1LinkedHashSet
4:Queue接口
继承接口Collection;通常而言,顺序是FIFO,例外是优先级队列(顺序由指定的Comparator来决定)和栈(LIFO)
增加了下面几个方法:
Throws exceptionReturns special valueInsert
add(e)
offer(e)
Removeremove()
poll()
Examineelement()
peek()
4.1:BlockingQueue接口
阻塞队列,当队列为空是取数据阻塞,队列满是,插入数据阻塞;是否是有界队列需要看具体的实现
Throws exceptionSpecial valueBlocksTimes outInsert
add(e)
offer(e)
put(e)
offer(e, time, unit)
Removeremove()
poll()
take()
poll(time, unit)
Examineelement()
peek()
not applicablenot applicable4.1.1:ArrayBlockingQueue
4.1.2:LinkedBlockingQueue
4.1.3:PriorityBlockingQueue
4.1.4:DelayQueue
4.2:Deque接口
双端队列First Element (Head)Last Element (Tail) Throws exceptionSpecial valueThrows exceptionSpecial valueInsert
addFirst(e)
offerFirst(e)
addLast(e)
offerLast(e)
RemoveremoveFirst()
pollFirst()
removeLast()
pollLast()
ExaminegetFirst()
peekFirst()
getLast()
peekLast()
继承了Queue接口,对应的方法实现
Queue MethodEquivalent Deque Method
add(e)
addLast(e)
offer(e)
offerLast(e)
remove()
removeFirst()
poll()
pollFirst()
element()
getFirst()
peek()
peekFirst()
也实现了LIFO栈,
Stack MethodEquivalent Deque Method
push(e)
addFirst(e)
pop()
removeFirst()
peek()
peekFirst()
4.2.1: BlockingDeque接口
阻塞式的双端队列First Element (Head) Throws exceptionSpecial valueBlocksTimes outInsert
FIFO的BlockingQueue
addFirst(e)
offerFirst(e)
putFirst(e)
offerFirst(e, time, unit)
RemoveremoveFirst()
pollFirst()
takeFirst()
pollFirst(time, unit)
ExaminegetFirst()
peekFirst()
not applicablenot applicableLast Element (Tail) Throws exceptionSpecial valueBlocksTimes outInsertaddLast(e)
offerLast(e)
putLast(e)
offerLast(e, time, unit)
RemoveremoveLast()
pollLast()
takeLast()
pollLast(time, unit)
ExaminegetLast()
peekLast()
not applicablenot applicableFIFO的BlockingQueue
BlockingQueue MethodEquivalent BlockingDeque MethodInsert
add(e)
addLast(e)
offer(e)
offerLast(e)
put(e)
putLast(e)
offer(e, time, unit)
offerLast(e, time, unit)
Removeremove()
removeFirst()
poll()
pollFirst()
take()
takeFirst()
poll(time, unit)
pollFirst(time, unit)
Examineelement()
getFirst()
peek()
peekFirst()
4.3PriorityQueue类
5:Map接口
保存的是键值对,不能有重复的key,每个key最多对应一个value;是否允许null和是否有序需要看具体的实现类;
equals方法的作用;
5.1ConcurrentMap接口
5.1.1ConcurrentHashMap
5.2SortedMap接口
5.2.1TreeMap
5.3HashMap类
5.3.1LinkedHashMap类
5.4Hashtable类
5.5WeakHashMap类
5.6IdentityHashMap类
0 0
- Java集合源码学习(1)_架构
- java学习_集合(1)
- java学习_集合
- java学习要点_集合
- java学习_集合(2)
- Java源码集合类HashMap学习1
- Java源码集合类LinkedHashMap学习1
- java源码分析之集合架构01
- Java集合架构____AbstractCollection源码解析
- java集合架构____HashMap源码分析
- java集合架构____LinkedHashMap及其源码分析
- java基础学习笔记_集合
- java集合架构(1)
- java源码分析之集合架构 Collection 02
- Java集合框架01-Collection架构与源码分析
- Java集合框架06--Map架构与源码分析
- java集合框架(二) Collection架构与源码分析
- Java集合源码学习(2)_Collection接口
- bupt暑假排位赛(1)
- poj_2935 Basic Wall Maze
- JspSmartUpload 实现下载
- 《Python基础教程》第20章学习笔记
- 【多级树形菜单-dialog自定义动画弹出方式-手势监听】dialog自定义动画
- Java集合源码学习(1)_架构
- httpd: Could not reliably determine the server's fully qualified domain name
- 【学习笔记】struts-tag与jstl的异同
- 黑马程序员-java方法
- How to Write Good Requirements
- LeetCode Reorder List
- POJ 1915Knight Moves
- SQL语句
- Lua: 给 Redis 用户的入门指导