Eclipse Collections - Sets 有 containsAny() 方法吗?

问题描述

我似乎在 Eclipse 集合中找不到 containsAny() 类型的 SetIterable 方法。有吗?

MutableSet<String> set1 = Sets.mutable.of("a","b","c");
ImmutableSet<String> set2 = Sets.immutable.of("c","d","e");

set1.containsAny(set2); // I can't find this method.

一个很容易:

/**
 * True if [set1] contains any element in [set2].
 */
public static <T> boolean intersects(SetIterable<T> set1,SetIterable<? extends T> set2) {
    return set1.intersect(set2).notEmpty();
}

但我只是想知道是否已经存在。

解决方法

我没有看到 containsAny 方法,但您可以这样做:

set2.anySatisfy(set1::contains);