Something like 'contains any' for Java set?

java

Solution

`Stream::anyMatch`

Since Java 8 you could use `Stream::anyMatch`.

setA.stream().anyMatch(setB::contains)

Problem

I have two sets, A and B, of the same type. I have to find if A contains any element from the set B. What would be the best way to do that without iterating over the sets? The Set library has `contains(object)` and `containsAll(collection)`, but not `containsAny(collection)`.

Original source