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
热门推荐
10 诗词送行祝福语大全简短
11 新房开工吉日祝福语简短
12 50多岁生日简短祝福语
13 安徽疫情祝福语简短英语
14 农民朋友发财祝福语简短
15 对生活祝福语简短精辟
16 搬家词简短祝福语朋友
17 女神结婚快乐祝福语简短
18 文学短句祝福语大全简短