noneMatch()Java中LongStream类的方法返回此流中是否没有元素与提供的谓词匹配。
语法如下
boolean noneMatch(LongPredicate predicate)
在此,参数谓词是无状态谓词,适用于此流的元素。但是,语法中的LongPredicate表示一个长值参数的谓词(布尔值函数)。
要在Java中使用LongStream类,请导入以下包
import java.util.stream.LongStream;
如果流中没有元素匹配提供的谓词,或者流为空,则该方法返回true。以下是noneMatch()在Java中实现LongStream方法的示例
import java.util.stream.LongStream;
public class Demo {
public static void main(String[] args) {
LongStream longStream = LongStream.of(10L, 20L, 30L, 40L);
boolean res = longStream.noneMatch(a -> a > 50);
System.out.println("None of the element match the predicate? "+res);
}
}由于没有元素与谓词匹配,因此返回True
输出结果
None of the element match the predicate? true
import java.util.stream.LongStream;
public class Demo {
public static void main(String[] args) {
LongStream longStream = LongStream.of(10L, 20L, 30L, 40L, 50, 60L);
boolean res = longStream.noneMatch(a -> a < 30L);
System.out.println("None of the element match the predicate? "+res);
}
}由于一个或多个元素与谓词匹配,因此返回False
输出结果
None of the element match the predicate? False