HashMap在Java开发中使用的非常频繁,可以说仅次于String,可以和ArrayList并驾齐驱,准备用几个章节来梳理一下HashMap.我们还是从定义一个HashMap开始. HashMap<String, Integer> mapData = new HashMap<>(); 我们从此处进入源码,逐步揭露HashMap /** * Constructs an empty <tt>HashMap</tt> with the default init…
其实HashMap就是一个Node数组,只是这个数组很奇怪它的每一个Node节点都有自己的下一个Node;这个是hashMap的Node的源码: static class Node<K,V> implements Map.Entry<K,V> { final int hash; final K key; V value; Node<K,V> next; Node(int hash, K key, V value, Node<K,V> next) { this…
1. 常量.成员变量 private static final int MAXIMUM_CAPACITY = 1 << 30; // 和HashMap一样 private static final int DEFAULT_CAPACITY = 16; // 和HashMap一样 static final int MAX_ARRAY_SIZE = Integer.MAX_VALUE - 8; // 和HashMap一样 static final int TREEIFY_THRESHOLD = 8…