CS-Notes打卡第六天--容器部分

五一划了两天水,赶快看看文章,等会继续leetcode周赛,估计又是白给23333

概览

Java中的容器分为Collection和Map两种,Collection存储着对象的集合,Map是存储着键值对(Map<key,value>)的映射表。

Collection

Collection接口的JavaDoc,表示相关联的类和接口

 * @param <E> the type of elements in this collection
 *
 * @author  Josh Bloch
 * @author  Neal Gafter
 * @see     Set
 * @see     List
 * @see     Map
 * @see     SortedSet
 * @see     SortedMap
 * @see     HashSet
 * @see     TreeSet
 * @see     ArrayList
 * @see     LinkedList
 * @see     Vector
 * @see     Collections
 * @see     Arrays
 * @see     AbstractCollection
 * @since 1.2
 */

下面是常用的集合类的继承关系,使用idea的Diagrams制作(Idea牛逼,Jetbrains牛逼)
在这里插入图片描述
Collection接口分别由Queue、List、Set继承

Queue

Queue表示单向链表,Deque接口是继承于Queue接口的双向链表接口

  1. PriorityQueue:基于堆结构实现,可以用它实现优先队列(需要提供排序规则)
  2. LinkedList:双向链表同时实现了List接口也是也可以作为双向队列来使用
  3. ArrayDeque:双向链表,也可以作为栈来使用(在栈Stack接口上面提示:A more complete and consistent set of LIFO stack operations is provided by the {@link Deque} interface and its implementations, which should be used in preference to this class. For example: {@code Deque stack = new ArrayDeque();})

List

List集合

  1. ArrayList:基于动态数组实现,可以进行随机访问
  2. Vector:与ArrayList相似,但是Vector是线程安全的(基于synchronized关键字进行同步)
  3. LinkedList:同时实现了Deque的双向队列的类

Set

Set集合

  1. TreeSet:基于红黑树的实现,支持有序性操作
  2. HashSet:基于哈希表的实现,但是不是有序的
  3. LinkedHashSet:继承于HashSet是一个双向的HashSet集合

Map

常见的Map类的继承关系
在这里插入图片描述

  1. HashMap:基于哈希表的实现
  2. ConcurrentHashMap:与HashMap相似,是线程安全的(继承于ReentrantLock来通过分段锁来确保线程安全)
  3. LinkedHashMap:使用双向链表来维持顺序,一般基于插入顺序或者最少使用顺序(LRU)
  4. HashTable:与HashMap相似,是线程安全的但是是时代的弃儿,从HashTable的JavaDoc可以得知(Java Collections Framework. Unlike the new collection
    implementations, {@code Hashtable} is synchronized. If a
    thread-safe implementation is not needed, it is recommended to use
    {@link HashMap} in place of {@code Hashtable}. If a thread-safe
    highly-concurrent implementation is desired, then it is recommended
    to use {@link java.util.concurrent.ConcurrentHashMap} in place of
    {@code Hashtable}.)
    5.TreeMap:基于红黑树的实现
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值