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 祝福语驱散霉运的话简短