Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Java Lambda style

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();
});
like image 435
bitsmcgee77 Avatar asked Dec 03 '22 10:12

bitsmcgee77


1 Answers

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.)

like image 130
Joe C Avatar answered Dec 25 '22 16:12

Joe C