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

如何在 Java 中拆分 HashMap

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

問(wèn)題描述

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

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

在我的例子中,我有一個(gè) 100 個(gè)元素的 HashMap,我想從原始元素創(chuàng)建 2 個(gè)(或更多)更小的 HashMap,第一個(gè)包含 0 到 49 的條目,第二個(gè)包含 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 非常適合這種事情.這是一個(gè)示例(注意 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);

這篇關(guān)于如何在 Java 中拆分 HashMap的文章就介紹到這了,希望我們推薦的答案對(duì)大家有所幫助,也希望大家多多支持html5模板網(wǎng)!

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

相關(guān)文檔推薦

Convert List of Strings into Map using Java-8 Streams API(使用 Java-8 Streams API 將字符串列表轉(zhuǎn)換為 Map)
Getting data from JSON(從 JSON 獲取數(shù)據(jù))
java linkedhashmap iteration(javalinkedhashmap迭代)
Converting a list of objects to Map(將對(duì)象列表轉(zhuǎn)換為 Map)
Create a HashMap with a fixed Key corresponding to a HashSet. point of departure(用一個(gè)固定的Key對(duì)應(yīng)一個(gè)HashSet創(chuàng)建一個(gè)HashMap.出發(fā)點(diǎn))
HttpMessageConverter exception : RestClientException: Could not write request: no suitable HttpMessageConverter found(HttpMessageConverter 異常:RestClientException:無(wú)法寫入請(qǐng)求:找不到合適的 HttpMessageConverter) - IT屋-程序員
主站蜘蛛池模板: 中文字幕第九页 | 欧美精品一二三 | 国产一区二区三区四区五区3d | 亚洲欧美中文字幕在线观看 | 精品国产一区一区二区三亚瑟 | 亚洲国产精品久久久久 | 国产在线精品一区二区三区 | av免费网| 91视频国产精品 | 国产一级片久久久 | 日韩国产专区 | av中文在线| 国产高清视频在线观看 | 色视频网站 | 日日摸日日爽 | 日韩一区二区视频 | 国产日产精品一区二区三区四区 | 欧美精品一区二区免费 | 亚洲精品免费视频 | 成人精品在线观看 | 中文字幕精品一区 | 一级片免费网站 | 成人精品视频在线观看 | 日干夜操| 国产亚洲一区精品 | 欧美黄色片| 日韩视频a| 中文字幕欧美一区 | 欧美aaaaa | 欧美精品在欧美一区二区 | 久久天天躁狠狠躁夜夜躁2014 | 中文视频在线 | 成人在线影视 | 欧美日一区二区 | 午夜精品一区二区三区在线播放 | 久久91精品国产一区二区 | 伊人久久一区二区 | 成人福利电影 | 国产高清视频 | 久久久综合网 | 成人一区二区视频 |