4

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();
});
1
  • You could always just use a for loop. Streams don't really get you anything here. Commented Oct 26, 2018 at 18:48

1 Answer 1

17

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

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.