有没有办法在流中使用多个 allMatch() 而不是使用以下形式?
Is there a way to use multiple allMatch() in a stream instead of using the below form?
return items.stream().allMatch(condition) && items.stream().allMatch(condition) &&
items.stream().allMatch(condition);
是的,您可以将所有条件添加到一个 allMatch
:
return items.stream().allMatch(condition && condtion2 && condition3)
这取决于你的逻辑,也许你可以使用比这更好的方法。
return items.stream().allMatch(condition) && items.stream().allMatch(condition) &&
items.stream().allMatch(condition);
是的,您可以将所有条件添加到一个 allMatch
:
return items.stream().allMatch(condition && condtion2 && condition3)
这取决于你的逻辑,也许你可以使用比这更好的方法。