文章目录
双列集合—Map
问题
1.Map 中的 Entry 接口是什么作用?
interface Entry<K,V>
- 1)HashMap/HashTable中:元素Node实现Map.Entry<K,V>接口)
static class Node<K,V> implements Map.Entry<K,V> {
final int hash;
final K key;
V value;
Node<K,V> next;
……
}
- 2)TreeMap中:元素Entry实现Map.Entry<K,V>接口
static final class Entry<K,V> implements Map.Entry<K,V> {
K key;
V value;
Entry<K,V> left;
Entry<K,V> right;
Entry<K,V> parent;
boolean color = BLACK;
……
}
- 3)LinkedHashMap中:元素 Entry 实现 继承自 HashMap.Node
static class Entry<K,V> extends HashMap.Node<K,V> {
Entry<K,V> before, after;
Entry(int hash, K key, V value, Node<K,V> next) {
super(hash