I have the following code that is functionally working
for (UniversityClass class : allClasses)
{
Period<Date> classDate = class.getClassDates();
if (classDate.start().before(classEndDate)
&& classDate.end().after(classBeginDate))
{
classBooked = true;
break;
}
}
I have tried this:
allClasses.stream().filter(class -> {
Period<Date> classDate = class.getClassDates();
if (classDate.start().before(classEndDate)
&& classDate.end().after(classBeginDate))
return true;
}).findFirst().ifPresent($ -> {
classBooked = true;
});
But this throws to add a return statement. Also, the classBooked variable needs to be declared final, but that cannot be done.
What is the mistake being done?
Also, once true, I need to break from it. that is why I thought of adding findFirst().ifPresent()