Java中hashMap的源码初探
最近一段时间准备沉下心来,认真学习底层的东西。今天从HashMap开始吧。看源码,我个人觉得应该带着问题去看,去学习大师们怎么做的。 {:toc} HashMap 底层是用什么数据结构实现的? HashMap 怎么扩容? HashMap 怎么解决Key冲突? HashMap 是线程安全的吗? HashMap 是怎么把数据均匀的分布到容器的? HashMap 底层是用什么数据结构实现的? 我们先来看看,HashMap实现类定义的变量: static final int DEFAULT_INITIAL_CAPACITY = 1 << 4; // aka 16 static final int MAXIMUM_CAPACITY = 1 << 30; static final float DEFAULT_LOAD_FACTOR = 0.75f; static final Entry<?,?>[] EMPTY_TABLE = {}; transient Entry<K,V>[] table = (Entry<K,V>[]) EMPTY_TABLE; transient int size; int threshold; final float loadFactor; transient int modCount; static final int ALTERNATIVE_HASHING