我有一个 ArrayList T 的声明
ArrayList<Integer> T = new ArrayList<Integer>();
我有一个 while 循环,它应该处于 Activity 状态,直到列表仅由 -1 个整数组成。目前它看起来像这样:
while(T.contains(!-1))
正如您可能猜到的那样。它无法正常工作,因为我无法对整数使用否定。
最佳答案
您可以使用Stream#allMatch
.
while(!T.stream().allMatch(i -> i == -1)){ // note the ! operator to negate the result
//do something
}
这应该继续循环,直到列表按照您的建议仅由 -1
整数组成。
关于JAVA 检查数组是否包含与给定值不同的值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44288942/