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

如何在 Java 中拆分 HashMap

How to split an HashMap in Java(如何在 Java 中拆分 HashMap)
本文介紹了如何在 Java 中拆分 HashMap的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

問題描述

我想知道是否可以將 HashMap 拆分為更小的子圖.

I was wondering if it is possible to split a HashMap into smaller sub-maps.

在我的例子中,我有一個 100 個元素的 HashMap,我想從原始元素創建 2 個(或更多)更小的 HashMap,第一個包含 0 到 49 的條目,第二個包含 50 到 99 的條目.

In my case I have a HashMap of 100 elements and I would like to create 2 (or more) smaller HashMaps from the original one, the first containing the Entries from 0 to 49, the second containing the Entries from 50 to 99.

Map <Integer, Integer> bigMap = new HashMap <Integer, Integer>();

//should contains entries from 0 to 49 of 'bigMap'
Map <Integer, Integer> smallMap1 = new HashMap <Integer, Integer>(); 


//should contains entries from 50 to 99 of 'bigMap'
Map <Integer, Integer> smallMap2 = new HashMap <Integer, Integer>();

有什么建議嗎?非常感謝!

Any suggestions? Many thanks!

推薦答案

一定要用HashMap嗎?

TreeMap 非常適合這種事情.這是一個示例(注意 0、50 和 99 是映射鍵,不是索引):

TreeMap is really good for this kind of things. Here's an example (note that 0, 50, and 99 are map keys, not indices):

TreeMap<Integer, Integer> sorted = new TreeMap<Integer, Integer>(bigMap);

SortedMap<Integer, Integer> zeroToFortyNine = sorted.subMap(0, 50); // toKey inclusive, fromKey exclusive
SortedMap<Integer, Integer> fiftyToNinetyNine = sorted.subMap(50, true, 99, true);

這篇關于如何在 Java 中拆分 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屋-程序員
主站蜘蛛池模板: 精品日韩一区二区 | 国产成人免费视频网站高清观看视频 | 欧美三级网站 | 日韩中文在线 | 国产福利视频 | 国产ts人妖系列高潮 | 亚洲精品成人av | 欧美成人aaa级毛片在线视频 | 亚洲精彩视频在线观看 | 91一区二区三区 | 欧美不卡在线 | 中文字幕在线免费视频 | 中文字幕高清一区 | 国产综合久久久久久鬼色 | 国产中文字幕在线观看 | 欧美在线视频一区 | 视频在线观看一区 | 一级毛片免费看 | 久久精品性视频 | 一区视频在线 | 国产精品久久九九 | 一级黄色生活视频 | 成年无码av片在线 | 国产 亚洲 网红 主播 | 天天曰夜夜| 羞羞视频免费在线 | 97久久超碰 | 操久久久| 天堂亚洲网 | 国产高清视频 | 97av在线 | 日韩av在线一区二区 | 日韩在线电影 | 黄色国产大片 | 国产中文字幕在线 | aa级毛片毛片免费观看久 | 九九色综合 | 亚洲 欧美 日韩在线 | 亚洲精品一区中文字幕乱码 | 91精品国产乱码久久久久久久久 | 精品久久久久久亚洲国产800 |