How to match stream elements but return false if non exists?

后端 未结 6 1744
无人共我
无人共我 2020-12-09 11:58

I have a stream and would like to check if all match a filter. If all match, return true.

But, if the stream is empty, I\'d like to return false

6条回答
  •  孤城傲影
    2020-12-09 12:28

    return !stream.filter(Whatever::someCheck).collect(Collectors.toList()).isEmpty()
    

提交回复
热议问题