Java中的IntStream noneMatch()方法
noneMatch()Java中的方法返回此流中是否没有元素与提供的谓词匹配。如果流中没有元素与提供的谓词匹配或流为空,则返回布尔值true。
语法如下
Boolean noneMatch(IntPredicate predicate)
在这里,参数谓词是应用于该流元素的无状态谓词
创建一个IntStream
IntStream intStream = IntStream.of(15, 25, 50, 60, 80, 100, 130, 150);
在这里,设置一个条件,该条件返回此流中是否没有元素与提供的谓词匹配。我们正在检查所有值都不小于10
boolean res = intStream.noneMatch(a -> a < 10);
以下是noneMatch()在Java中实现IntStream方法的示例。它检查是否没有元素
示例
import java.util.*;
import java.util.stream.IntStream;
public class Demo {
public static void main(String[] args) {
IntStream intStream = IntStream.of(15, 25, 50, 60, 80, 100, 130, 150);
boolean res = intStream.noneMatch(a -> a < 10);
System.out.println(res);
}
}输出结果
true