hashmap get
时间: 2023-08-24 19:09:52 浏览: 89
HashMap的get方法是用来获取指定key对应的value的。在红黑树中获取节点时,会通过判断key是否实现了Comparable接口来确定是否有序。具体实现中,通过hash(key)方法获取key在node数组下的位置,然后通过getNode方法获取对应的节点。如果节点为空,则返回null,否则返回节点的value值。\[1\]\[2\]所以,HashMap的get方法是通过计算hash值和比较key来进行寻值的,无论是在红黑树还是在链表中,寻值的过程都是相对简单的。\[3\]
#### 引用[.reference_title]
- *1* *3* [HashMap之get方法详解](https://blog.csdn.net/weixin_39667787/article/details/86687414)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v91^control,239^v3^insert_chatgpt"}} ] [.reference_item]
- *2* [HashMap中get方法详解](https://blog.csdn.net/lubiaojava/article/details/119779611)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v91^control,239^v3^insert_chatgpt"}} ] [.reference_item]
[ .reference_list ]
阅读全文