如何解决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);
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。