Java 中的 IntStream noneMatch() 方法
java 8object oriented programmingprogramming
Java 中的 noneMatch() 方法返回此流中是否有元素与提供的谓词匹配。如果流中没有元素与提供的谓词匹配,或者流为空,则返回 true 布尔值。
语法如下
Boolean noneMatch(IntPredicate predicate)
此处,参数 predicate 是应用于此流元素的无状态谓词
创建一个 IntStream
IntStream intStream = IntStream.of(15, 25, 50, 60, 80, 100, 130, 150);
此处设置一个条件,返回此流中是否没有任何元素与提供的谓词匹配。我们检查是否存在小于 10 的值。
boolean res = intStream.noneMatch(a -> a < 10);
以下是在 Java 中实现 IntStream noneMatch() 方法的示例。它检查是否存在元素。
示例
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