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 好听的元旦简短祝福语