Java中的IntStream anyMatch()方法
anyMatch()Java中IntStream类中的方法返回此流的任何元素是否与提供的谓词匹配。
语法如下
boolean anyMatch(IntPredicate predicate)
要使用Java中的IntStream类,请导入以下包
import java.util.stream.IntStream;
在此,谓词参数是无状态谓词,可应用于此流的元素。
创建一个IntStream并添加一些元素
IntStream intStream = IntStream.of(20, 40, 60, 80, 100);
现在,使用该anyMatch()方法设置条件。如果任何元素与条件匹配,则返回TRUE
boolean res = intStream.anyMatch(a -> a < 50);
以下是anyMatch()在Java中实现IntStream方法的示例
示例
import java.util.stream.IntStream;
public class Demo {
public static void main(String[] args) {
IntStream intStream = IntStream.of(20, 40, 60, 80, 100);
boolean res = intStream.anyMatch(a -> a < 50);
System.out.println(res);
}
}发现小于50的值,因此返回true
输出结果
true
热门推荐
10 家人毕业祝福语简短励志
11 毕业祝福语简短给同学
12 鱼的内涵简短祝福语
13 送给姐姐简短的祝福语
14 叶海燕老师祝福语简短
15 新年的好祝福语简短
16 祝产妇的祝福语简短
17 新年简短的英文祝福语
18 元旦祝福语简短有深度