I have hashmap: Map<String, Set<String>> myMap
and I want to split it to list that contains Map
:
List<Map<String,Set<String>>> listofMaps;
, and each map will be max 100 keys.
I know how to do it in the regular way..(foreach on the entryset , and every 100 items create new map).
Is there any option to do it with java 8 lambda or something? (something like Lists.partitions()
..) ?
Using my unorderedBatches()
collector from this answer:
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);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With