IntStream allMatch() 方法在 Java 中
Java 中 IntStream 类的 allMatch() 方法返回此流的所有元素是否都匹配提供的谓词。
语法如下
boolean allMatch(IntPredicate predicate)
此处,predicate 参数是对此流的元素应用的无状态谓词。IntPredicate 表示一个 int 值参数的谓词。
如果流的所有元素都匹配提供的谓词,或者流为空,则 allMatch() 方法返回 true。
以下是使用 Java 中的 IntStream allMatch() 方法的示例
示例
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
广告
数据结构
网络
RDBMS
操作系统
Java
iOS
HTML
CSS
Android
Python
C 编程
C++
C#
MongoDB
MySQL
Javascript
PHP