GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — :bug: Fixing a bug. LinkedHashMap · sustbeckham/Java-Interview@54cb082

File tree

Expand file treeCollapse file tree
Open diff view settings
Filter options
  • MD/collection
    • LinkedHashMap.md
Expand file treeCollapse file tree
Open diff view settings
Collapse file

‎MD/collection/LinkedHashMap.md‎

Copy file name to clipboardExpand all lines: MD/collection/LinkedHashMap.md
+15-1Lines changed: 15 additions & 1 deletion
  • Display the source diff
  • Display the rich diff
Original file line numberDiff line numberDiff line change
@@ -238,10 +238,24 @@ LinkedHashMap 的 `get()` 方法也重写了:
238238
if (e == null)
239239
return null;
240240

241-
//多了一个判断是否是按照访问顺序排序,是则将当前的 Entry 移动到链表末尾
241+
//多了一个判断是否是按照访问顺序排序,是则将当前的 Entry 移动到链表头部。
242242
e.recordAccess(this);
243243
return e.value;
244244
}
245+
246+
void recordAccess(HashMap<K,V> m) {
247+
LinkedHashMap<K,V> lm = (LinkedHashMap<K,V>)m;
248+
if (lm.accessOrder) {
249+
lm.modCount++;
250+
251+
//删除
252+
remove();
253+
//添加到头部
254+
addBefore(lm.header);
255+
}
256+
}
257+
258+
245259
```
246260

247261
`clear()` 清空就要比较简单了:

0 commit comments

Comments
0 (0)
You are visitor 01402792 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.