One article to get ArrayList, LinkedList, HashMap, HashSet -----Source code interpretation of ArrayList
to get ArrayList, LinkedList, HashMap, HashSet ----- Source code interpretation of LinkedList
to get ArrayList, LinkedList, HashMap, HashSet ----- Source code interpretation of HashMap
article to get ArrayList, LinkedList, HashMap, HashSet ----- source code interpretation of HashSet
The source code of HashMap is defined in this way.
The Cloneable and Serializable interfaces are explained in the previous ArrayList source code interpretation.
public class HashMap<K,V> extends AbstractMap<K,V>
implements Map<K,V>, Cloneable, Serializable
HashMap inherits AbstractMap
and implements the Map
interface
HashMap has a lot of content, which is convenient for better interpretation of the source code. First, the internal structure of HashMap is simplified.
Please read my other article on HashMap's comments and simplifications, which is easy to remember
Article transfer == " Simplify HashMap
在JDK1.2源码的数据结构
The bottom layer of HashMap in jdk1.2 is 链表+数组
the structure of the real data storage as follows
private transient Entry table[];//数组
private static class Entry implements Map.Entry {
int hash; // key的hash值
Object key; // 键
Object value; // 值
Entry next; // 下一个节点
Entry(int hash, Object key, Object value, Entry next) {
this.hash = hash;
this.key = key;
this.value = value;
this.next = next;
}
}
The early HashMap used a linked list structure to solve the same index value and hash conflict to store the same index but different value data. The reason why it was designed as a linked list + array is to store the data more compactly, save memory space, and facilitate expansion.