I have a Stream<Integer>
and want to know if there is a null
in this stream. How do I check that? Using .anyMatch(null)
throws me a java.lang.NullPointerException
.
我有一个流
1 个解决方案
#1
17
anyMatch
accepts a predicate.
anyMatch接受一个谓词。
stream.anyMatch(x -> x == null)
or
或
stream.anyMatch(Objects::isNull)
#1
17
anyMatch
accepts a predicate.
anyMatch接受一个谓词。
stream.anyMatch(x -> x == null)
or
或
stream.anyMatch(Objects::isNull)