Find if a Map contains a value from a Set

Viewed 378

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?

1 Answers
boolean contains = foo.stream()
                      .anyMatch(map::containsKey);

Not sure if that is cooler.

Related