Java – how do I check if NULL is in the stream?

I have a stream < integer > and want to know if there is space in this stream How to check? use. Anymatch (null) gives me a Java lang.NullPointerException.

Solution

Anymatch accepts predicates

stream.anyMatch(x -> x == null)

or

stream.anyMatch(Objects::isNull)
The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>