我编造了这个小助手类,想知道是否可以从任何地方窃取它而不是重新实现轮子:
public class Booleans3 {
private Booleans3(){}
public static boolean and(Iterable<Boolean> booleans) {
boolean result = true;
for (Boolean boolRef : booleans) {
boolean bool = boolRef;
result &= bool;
}
return result;
}
public static boolean or(Iterable<Boolean> booleans) {
boolean result = false;
for (Boolean boolRef : booleans) {
boolean bool = boolRef;
result |= bool;
}
return result;
}
}
我看了com.google.common.primitives.Booleans , 它似乎没有包含我需要的东西。
最佳答案
这个怎么样:
public static boolean and(Collection<Boolean> booleans)
{
return !booleans.contains(Boolean.FALSE);
}
public static boolean or(Collection<Boolean> booleans)
{
return booleans.contains(Boolean.TRUE);
}
关于java - 在任何标准库中是否有帮助程序类实现对 boolean 集合的逻辑操作?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8786446/