Reputation: 391
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();
});
Upvotes: 4
Views: 159
Reputation: 15674
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
.)
Upvotes: 17