Java中的IntStream allMatch()方法
allMatch()Java中IntStream类的方法返回此流的所有元素是否与提供的谓词匹配。
语法如下
boolean allMatch(IntPredicate predicate)
在此,谓词参数是适用于此流元素的无状态谓词。IntPredicate表示一个int值参数的谓词。
allMatch()如果流中的所有元素都与提供的谓词匹配,或者流为空,则该方法返回true。
以下是allMatch()在Java中实现IntStream方法的示例
示例
import java.util.*;
import java.util.stream.IntStream;
public class Demo {
public static void main(String[] args) {
IntStream intStream = IntStream.of(55, 65, 70, 90, 100);
boolean res = intStream.allMatch(a -> a > 50);
System.out.println("Does all the elements of the stream matches the predicate?"+res);
}
}输出结果
Does all the elements of the stream matches the predicate?true
示例
import java.util.*;
import java.util.stream.IntStream;
public class Demo {
public static void main(String[] args) {
IntStream intStream = IntStream.of(15, 20, 25, 40, 50, 80);
boolean res = intStream.allMatch(a -> a < 30);
System.out.println("Do all the elements of the stream match the predicate? "+res);
}
}输出结果
Do all the elements of the stream match the predicate? False
热门推荐
6 保研的祝福语简短
10 年轻20岁祝福语简短
11 朋友结婚祝福语信息简短
12 女孩婚礼贺卡祝福语简短
13 30段点歌简短祝福语
14 虎年春节祝福语图文简短
15 写给后妈祝福语大全简短
16 简短回复生日祝福语
17 校长送毕业祝福语简短
18 毕业立体贺卡祝福语简短