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 妈妈生日祝福语简短励志