最外层数据存储在Entry数组中,拥有相同hashcode的Entry由next属性关联
/**
* The table, resized as necessary. Length MUST Always be a power of two.
*/
transient Entry[] table;
HashMap内部类
static class Entry implements Map.Entry {
final K key;
V value;
Entry next;
final int hash;
/**
* Creates new entry.
*/
Entry(int h, K k, V v, Entry n) {
value = v;
next = n;
key = k;
hash = h;
}
...省略...
}
用箭头相连的Entry都有相同的hashcode值
最外层数据由Segment数组来管理,Segment中数据又由HashEntry来进行管理,最终数据是存在HashEntry对象中,拥有相同hashcode值的对象有HashEntry的next属性来进行关联
/**
* The segments, each of which is a specialized hash table
*/
final Segment[] segments;
ConcurrentHashMap内部类
static final class HashEntry {
final K key;
final int hash;
volatile V value;
final HashEntry next;
HashEntry(K key, int hash, HashEntry next, V value) {
this.key = key;
this.hash = hash;
this.next = next;
this.value = value;
}}
用箭头相连的HashEntry都有相同的hashcode值
ArrayList是由数组来存储对象的
/**
* The array buffer into which the elements of the ArrayList are stored.
* The capacity of the ArrayList is the length of this array buffer.
*/
private transient Object[] elementData;
LinkedList数据是存在Entry对象里的,LikedList对象里默认会有一个名为header的Entry对象;
在向LinkedList中添加元素时,会自动修改该对象的next和previous属性,使集合中所有对象通过next和previous关联关系能形成一个闭合的环状结构
LinkedList内部类
private static class Entry {
E element;
Entry next;
Entry previous;
Entry(E element, Entry next, Entry previous) {
this.element = element;
this.next = next;
this.previous = previous;
}
}
以添加第一个元素后结果示例(header元素是创建LinkedList对象后就默认存在的)