So, this doesn't work, since seatsAvailable is final. How can what I'm trying to accomplish be done using more of a lambda-style-from-the-ground-up way?
final boolean seatsAvailable = false;
theatreSeats.forEach(seat -> {
if (!seatsAvailable) seatsAvailable = seat.isEmpty();
});
It looks like you want seatsAvailable
to be true
if there is at least one empty seat. Therefore, this should do the trick for you:
final boolean seatsAvailable = theatreSeats.stream().anyMatch(Seat::isEmpty);
(Note: I am assuming that your class is named Seat
.)
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