Tal*_*den 2 java collections hashmap java-8
我有哈希图: Map<String, Set<String>> myMap
我想将其拆分为包含Map以下内容的列表:
List<Map<String,Set<String>>> listofMaps;
Run Code Online (Sandbox Code Playgroud)
,每张地图最多可包含100个键。我知道如何以常规方式执行此操作。(在entryset上进行foreach,每100个项目会创建一个新地图)。有什么选择可以用Java 8 lambda或其他东西吗?(有点像Lists.partitions()..)?
使用我的unorderedBatches()收集器从这个答案:
Collector<Entry<String, Set<String>>, ?, List<Map<String, Set<String>>>> batchesCollector =
unorderedBatches(100,
Collectors.toMap(Entry::getKey, Entry::getValue), Collectors.toList());
List<Map<String, Set<String>>> listofMaps = myMap.entrySet().stream()
.collect(batchesCollector);
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
7984 次 |
| 最近记录: |