)p).getTreeNode(hash, key);----------------------------------------------------------//当前桶位为链表else {do {if (e.hash == hash &&((k = e.key) == key ||(key != null && key.equals(k)))) {node = e;break;}p = e;} while ((e = e.next) != null);}}----------------------------------------------------------//判断node不为空的情况,说明按照key找到了要删除的数据if (node != null && (!matchValue || (v = node.value) == value ||(value != null&&value.equals(v)))) {//结果是红黑树if (node instanceof TreeNode)((TreeNode)node).removeTreeNode(this, tab, movable);//结果为单个元素else if (node == p)tab[index] = node.next;//结果为链表elsep.next = node.next;++modCount;//修改次数自增--size;//长度减少afterNodeRemoval(node);return node;}}return null;}
7.方法分析
【面试收藏!!!HashMap底层原理剖析】@Overridepublic boolean replace(K key, V oldValue, V newValue) {Node e; V v;if ((e = getNode(key)) != null &&((v = e.value) == oldValue || (v != null && v.equals(oldValue)))) {e.value = http://www.kingceram.com/post/newValue;afterNodeAccess(e);return true;}return false;}----------------------------------------------------------@Overridepublic V replace(K key, V value) {Node e;if ((e = getNode(key)) != null) {V oldValue = e.value;e.value = value;afterNodeAccess(e);return oldValue;}return null;}ll && v.equals(oldValue)))) {e.value = http://www.kingceram.com/post/newValue;afterNodeAccess(e);return true;}return false;}----------------------------------------------------------@Overridepublic V replace(K key, V value) {Node e;if ((e = getNode(key)) != null) {V oldValue = http://www.kingceram.com/post/e.value;e.value = value;afterNodeAccess(e);return oldValue;}return null;}