I have a list of objects from which I extract the booleans and want to apply the AND operation on them. Is there a better (or more concise) way to do this?
final boolean[] result = {true};
someList.stream().map(o -> o.getBooleanMember()).forEach(b -> result = result && b);
You can use reduce
:
boolean result = someList.stream().map(o -> o.getBooleanMember()).reduce(true,(a,b)->a&&b);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With