【问题标题】:Eclipse Collections - Is there a containsAny() method for Sets?Eclipse Collections - Sets 是否有 containsAny() 方法?
【发布时间】:2021-06-09 22:23:21
【问题描述】:

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

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();
}

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

【问题讨论】:

标签: java eclipse-collections


【解决方案1】:

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

set2.anySatisfy(set1::contains);

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-01-25
    • 1970-01-01
    • 2018-10-01
    • 1970-01-01
    • 2017-06-06
    • 1970-01-01
    相关资源
    最近更新 更多