当前位置: 首页 > news >正文

java系列-LinkedHashMap

1.插入新节点时,会将该节点加到链表尾部

 

public class LinkedHashMap<K,V> extends HashMap<K,V> implements Map<K,V>{/*** The head (eldest) of the doubly linked list.*/transient LinkedHashMapEntry<K,V> head;/*** The tail (youngest) of the doubly linked list.*/transient LinkedHashMapEntry<K,V> tail;Node<K,V> newNode(int hash, K key, V value, Node<K,V> e) {LinkedHashMapEntry<K,V> p = new LinkedHashMapEntry<K,V>(hash, key, value, e);linkNodeLast(p);return p;}// link at the end of listprivate void linkNodeLast(LinkedHashMapEntry<K,V> p) {LinkedHashMapEntry<K,V> last = tail;tail = p; //更新p为尾节点if (last == null){ //如果之前尾节点为null,说明链表为null,那更新头节点为phead = p;} else {p.before = last;last.after = p;}}
}

2. 移除一个元素后,会将该元素从链表移除

 

public class LinkedHashMap<K,V> extends HashMap<K,V> implements Map<K,V> {void afterNodeRemoval(Node<K,V> e) { // unlinkLinkedHashMapEntry<K,V> p = (LinkedHashMapEntry<K,V>)e, b = p.before, a = p.after;p.before = p.after = null;if (b == null){//之前p为headhead = a;//更新p的下一个元素为head} else{b.after = a;}if (a == null){//之前p为tailtail = b;} else{a.before = b;}}
}

http://www.lryc.cn/news/258303.html

相关文章:

  • 【linux】查看CPU和内存信息
  • 【产品经理】产品专业化提升路径
  • Ubuntu(WSL)卸载与安装指定版本的 openssl
  • leetcode1115. 交替打印 FooBar
  • qt有哪些常用控件
  • docker 手工redis7.x cluster
  • 【华为OD题库-082】TLV解析II-Java
  • Memcached学习
  • 2024最新金三银四软件测试面试题
  • 微信小程序动态加载图表[echart]
  • 《opencv实用探索·十八》Camshift进行目标追踪流程
  • MAP: Multimodal Uncertainty-Aware Vision-Language Pre-training Model
  • 【SpringCache】快速入门 通俗易懂
  • GeoTools学习笔记
  • 短剧规模达到了百亿元,短剧分销成为短剧新模式
  • Kotlin 中的 `as` 关键字:类型转换的艺术
  • CDN可以给企业网站带来哪些优势?
  • 离线运行Oracle Database In-Memory Advisor
  • 2,PyCharm的下载与安装
  • HNU计算机视觉作业一
  • Java:SpringBoot获取当前运行的环境activeProfile
  • 射频功率放大器的参数有哪些
  • 3-5、多态性
  • 什么是https 加密协议?
  • 低压无功补偿在分布式光伏现场中的应用
  • 人工智能技术在宽域飞行器控制中的应用
  • NGINX高性能服务器与关键概念解析
  • 云ssrf
  • 面试题目总结(三)
  • Kubernetes入门笔记——(2)k8s设计文档