Java中的LongStream noneMatch()方法
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
热门推荐
1 带狗狗训练
4 听力训练狗狗
6 怎训练狗狗
7 腹肌训练狗狗
8 网球训练狗狗
9 记叙文训练狗狗
10 狗狗太凶怎么训练
11 核心力量训练狗狗
12 狗狗乱叫怎么训练
13 发音训练狗狗
14 怎么训练狗狗叼东西给主人
15 荆州训练狗狗
16 篮球训练狗狗
17 做训练狗狗
18 训练狗狗坐姿