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
热门推荐
1 训练狗狗工作
4 狗狗定点排便训练
5 狗狗训练吠叫
6 狗狗尿垫训练
7 狗狗训练座
8 狗狗训练攻略
9 狗狗训练记
10 做训练狗狗
11 狗狗训练词
12 狗狗谢谢怎么训练
13 狗狗训练如厕
14 狗狗太凶怎么训练
15 狗狗训练它
16 狗狗克制训练
17 训练基地狗狗
18 怎么样训练狗狗大小硬