Java Lambda style

  • A+

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 =; 

(Note: I am assuming that your class is named Seat.)


:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen: