So, I want to make a new map from the old one. In the new Map<String, Integer>
the String key denotes the same key as in the first map and the Integer value denotes the size of the corresponding List<Something>
. I want to make the transformation using Java 8 streams. I tried something like, but it gives me errors.
Map<String, List<Something>> map1=.....
Map<String, Integer> map2;
map2=map1.entrySet().stream().collect(Collectors.toMap(p-> p.getKey(), p->getValue().size()));
It missing p
before getValue()
map2 = map1.entrySet().stream()
.collect(Collectors.toMap(p -> p.getKey(), p -> p.getValue().size()));
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments