【问题标题】:Is there a way to use multiple allMatch() in a stream instead of using the below form?有没有办法在流中使用多个 allMatch() 而不是使用下面的形式?
【发布时间】:2021-09-09 06:37:16
【问题描述】:
return items.stream().allMatch(condition) && items.stream().allMatch(condition) && 
    items.stream().allMatch(condition);

【问题讨论】:

  • 如果您分享什么条件,也许我们可以提出其他解决方案!

标签: java java-8 java-stream


【解决方案1】:

是的,您可以在一个allMatch 中添加所有条件:

return items.stream().allMatch(condition && condtion2 && condition3)

这取决于你的逻辑,也许你可以使用比这更好的。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2019-02-27
    • 1970-01-01
    • 2020-12-06
    • 1970-01-01
    • 2015-04-21
    • 2014-06-07
    • 2021-07-02
    相关资源
    最近更新 更多