Split LinkedHashMap <string,list <object =“”>&gt; chunkMap = new LinkedHashMap <string,list <object =“”>&gt;()成相等的分区

时间:2018-05-07 23:05:20

标签: java hashmap linkedhashmap

我有一个LinkedHashMap,我想把它拆分成相等的分区。

LinkedHashMap<String, List<object>> chunkMap = new LinkedHashMap<String, List<object>>();

例如,如果我的地图中有10个键,我想将其分区为5,这意味着我分区后应该有2个地图。

1 个答案:

答案 0 :(得分:0)

List<Object> chunkArrayList = new ArrayList<Object>();
 for (int i = 0; i < randomList.size(); i++) {
        chunkArrayList.add(i, randomList.get(i));
 }

for (start = 0; start < chunkArrayList.size(); start += 5) {
  end = Math.min(start + 5, chunkArrayList.size());
  List<Form> Sublist = chunkArrayList.subList(start, end);
      //My code
}

Above code I have is for List and that works very fine. But now I have map and i'm not sure how can I do it.

 LinkedHashMap<String, List<Object>> roleNumMap= new LinkedHashMap<String, List<Object>>();

getRoleNumber(null, null, new ArrayList<String>(roleNumMap.keySet()), null, null)

很抱歉我以前的帖子不清楚。在此先感谢:)