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 简短祝福语毛笔字