我想知道是否有可能将HashMap拆分为更小的子地图。如何在Java中拆分HashMap
在我的情况下,我有一个HashMap的100个元素,我想从原始创建2个(或更多)较小的HashMap,第一个包含从0到49的条目,第二个包含从50到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>();
有什么建议吗?非常感谢!
谢谢我会尝试 – RNO
downvoter护理评论为什么这不是一个好的答案? – sharakan
我不知道为什么你收到了一些downvote,我选择了你的答案,因为它不会浪费太多的记忆。 TreeMap使我能够高效地实现我想要的。附:我应该指出,结果应该是表现出来的,而你的建议就是这样。再次感谢 – RNO