久久久久久久av_日韩在线中文_看一级毛片视频_日本精品二区_成人深夜福利视频_武道仙尊动漫在线观看

Java - 關于沖突處理和 get() 方法的 HashMap 混淆

Java - HashMap confusion about collision handling and the get() method(Java - 關于沖突處理和 get() 方法的 HashMap 混淆)
本文介紹了Java - 關于沖突處理和 get() 方法的 HashMap 混淆的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

問題描述

我正在使用 HashMap,但我無法直接回答 get() 方法在發生沖突時如何工作.

I'm using a HashMap and I haven't been able to get a straight answer on how the get() method works in the case of collisions.

假設 n >1 個對象被放置在同一個 key 中.它們是否存儲在 LinkedList 中?它們是否被覆蓋,以便僅放置在該鍵中的最后一個對象不再存在?他們是否使用了其他碰撞方法?

Let's say n > 1 objects get placed in the same key. Are they stored in a LinkedList? Are they overwritten so that only the last object placed in that key exists there anymore? Are they using some other collision method?

如果將它們放在 LinkedList 中,有沒有辦法檢索整個列表?如果沒有,是否有其他的 Java 內置地圖可供我執行此操作?

If they are placed in a LinkedList, is there a way to retrieve that entire list? If not, is there some other built in map for Java in which I can do this?

就我的目的而言,單獨的鏈接將是理想的,就好像存在沖突一樣,我需要能夠查看列表并獲取有關其中所有對象的信息.在 Java 中執行此操作的最佳方法是什么?

For my purposes, separate chaining would be ideal, as if there are collisions, I need to be able to look through the list and get information about all the objects in it. What would be the best way to do this in Java?

感謝您的幫助!

推薦答案

它們是否被覆蓋,從而只有放置在該鍵中的最后一個對象不再存在?

Are they overwritten so that only the last object placed in that key exists there anymore?

是的,假設您使用相同的鍵放置多個值(根據 Object.equals,而不是 Object.hashCode.)這是在 Map.put javadoc:

Yes, assuming you're putting multiple values with the same key (according to Object.equals, not Object.hashCode.) That's specified in the Map.put javadoc:

如果映射先前包含鍵的映射,則舊值將替換為指定值.

If the map previously contained a mapping for the key, the old value is replaced by the specified value.

如果您想將一個鍵映射到多個值,最好使用 Guava 的 ListMultimap, ArrayListMultimap 具體而言,它將鍵映射到值列表.(披露:我為 Guava 做出了貢獻.)如果你不能容忍第三方庫,那么你真的必須有一個 Map<Key, List<Value>>,盡管這可以得到有點笨拙.

If you want to map a key to multiple values, you're probably better off using something like Guava's ListMultimap, ArrayListMultimap in specific, which maps keys to lists of values. (Disclosure: I contribute to Guava.) If you can't tolerate a third-party library, then really you have to have a Map<Key, List<Value>>, though that can get a bit unwieldy.

這篇關于Java - 關于沖突處理和 get() 方法的 HashMap 混淆的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!

【網站聲明】本站部分內容來源于互聯網,旨在幫助大家更快的解決問題,如果有圖片或者內容侵犯了您的權益,請聯系我們刪除處理,感謝您的支持!

相關文檔推薦

Convert List of Strings into Map using Java-8 Streams API(使用 Java-8 Streams API 將字符串列表轉換為 Map)
Getting data from JSON(從 JSON 獲取數據)
java linkedhashmap iteration(javalinkedhashmap迭代)
Converting a list of objects to Map(將對象列表轉換為 Map)
Create a HashMap with a fixed Key corresponding to a HashSet. point of departure(用一個固定的Key對應一個HashSet創建一個HashMap.出發點)
HttpMessageConverter exception : RestClientException: Could not write request: no suitable HttpMessageConverter found(HttpMessageConverter 異常:RestClientException:無法寫入請求:找不到合適的 HttpMessageConverter) - IT屋-程序員
主站蜘蛛池模板: 欧美日韩亚洲国产综合 | 一级aaaa毛片 | 欧美视频三区 | 成人在线免费观看视频 | 91精品国产一区二区 | 午夜理伦三级理论三级在线观看 | 国产精品免费一区二区三区四区 | 91视在线国内在线播放酒店 | 国产99久久精品一区二区300 | 久久在线精品 | 日韩一区二区三区四区五区六区 | 亚洲国产成人在线 | 欧美日韩福利视频 | 国产成人久久精品一区二区三区 | 欧美一区二区在线观看 | 国产精品成人国产乱 | 欧美成人精品一区二区男人看 | 亚洲人在线 | 国产精品亚洲一区二区三区在线 | 亚洲aⅴ| 欧美久久久久久久久中文字幕 | 看毛片网站| 欧美成人精品在线 | 91av在线不卡 | 亚洲成人一区二区 | 亚洲视频一区 | 蜜桃毛片 | 成人一区二区三区 | 福利影院在线看 | 日韩毛片免费看 | 亚洲激情在线观看 | 中文字幕亚洲视频 | 国产激情一区二区三区 | 国产精品免费av | 欧美日韩久久久 | 国精产品一品二品国精在线观看 | 国产视频一区二区在线观看 | www.亚洲一区| 成人免费视频观看视频 | 在线免费看黄 | 午夜亚洲|