java集合源码
爱Ta的猫
年轻是我们的资本,但不是我们说不会的理由。
以后的某一天,现在不会的东西就都会了!
展开
-
ArrayList
ArrayList *** 结构** 底层是数组实现,有序,可重复的集合 //默认arrayList容量 private static final int DEFAULT_CAPACITY = 10; //存储arrayList数据的数组 transient Object[] elementData; //集合大小 private int size; //构造方法,都是比较容易理解的构造方法 public ArrayList(int initialCapacity) { if (initi原创 2021-04-27 15:58:40 · 73 阅读 · 0 评论 -
LinkedList
LinkedList* *** 结构** 基于链表结构的双向列表,有序可重复 //集合大小 transient int size = 0; /** * 指向第一个节点的指针 */ transient Node<E> first; /** * 指向最后一个节点的指针 */ transient Node<E> last; //内部类,指针Node private static class Node<E> { //元素 E item;原创 2021-04-27 16:14:41 · 75 阅读 · 0 评论 -
HashSet-TreeSet-LinkedHashSet-Vector
HashSet *** 结构** HashSet按Hash算法来储存集合中的元素,无序且不重复,底层是由HashMap实现 private transient HashMap<E,Object> map; // Dummy value to associate with an Object in the backing Map private static final Object PRESENT = new Object(); //构造方法 public HashSet() {原创 2021-04-27 16:02:13 · 85 阅读 · 0 评论 -
TreeMap
TreeMap* *** 结构** TreeMap基于红黑树对SortedMap进行排序的键值对,排序方式由创建时传入的参数决定,不传为null, /** * The comparator used to maintain order in this tree map, or * null if it uses the natural ordering of its keys. * 比较器用于维护此树形图中的顺序,如果比较器使用其键的自然顺序,则为null。 * @原创 2021-04-27 16:02:39 · 81 阅读 · 0 评论 -
HashMap
HashMap *** 结构** HashMap基于哈希表的实现。该实现提供了所有可选的映射操作,并允许null 值和null键。此类不保证map的顺序,JDK1.8中,HashMap采用数组+单向链表+红黑树实现,当链表长度超过阈值(8)时,将链表转换为红黑树, HashMap相同hash值,但是equals结果不相等的键值对会在同一条单向链表或红黑树中 //默认容量 static final int DEFAULT_INITIAL_CAPACITY = 1 << 4; // aka 16 /原创 2021-04-27 16:03:33 · 72 阅读 · 0 评论 -
LinkedHashMap
LinkedHashMap *** 结构** 在继承HashMap的基础上,通过一个链表来维持顺序 HashMap中的Entry,next用于维护每个桶中的单链表 hash key value next LinkedHashMap中的Entry,before,after用于维护整个双链表 before hash key value next after /** * HashMap.Node subclass for normal LinkedHashMap entrie原创 2021-04-27 16:04:05 · 130 阅读 · 0 评论 -
HashTabel
HashTabel *** 结构** Hashtable 的函数都是同步的,这意味着它是线程安全的。它的key、value都不可以为null。 Hashtable中的映射不是有序的。 //存储元素的节点数组 private transient Entry<?,?>[] table; //总量 private transient int count; //当表的大小超过此阈值时,将对其进行重新哈希处理。(此字段的值为(int)(容量* loadFactor)) private int thresh原创 2021-04-27 16:04:38 · 134 阅读 · 0 评论