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
热门推荐
10 对患者生日祝福语简短
11 结婚祝福语简短装备
12 周岁祝福语学生文案简短
13 订婚领证祝福语简短精辟
14 导师获奖祝福语大全简短
15 新婚购房祝福语简短精辟
16 牛年祝福语简短的爱人
17 送芒果的祝福语简短
18 送给学长毕业祝福语简短