I want to see if any value in my Set is used in as a key in a Map.
I could do:
Set<String> foo;
for (String val: foo) {
if (map.containsKey(val)) {
contains = true;
break
}
}
Is there anything cooler?
I want to see if any value in my Set is used in as a key in a Map.
I could do:
Set<String> foo;
for (String val: foo) {
if (map.containsKey(val)) {
contains = true;
break
}
}
Is there anything cooler?
boolean contains = foo.stream()
.anyMatch(map::containsKey);
Not sure if that is cooler.