Java Lambda - check if an ArrayList to Stream is empty
I have the following lambda expression and if works fine when bonusScheduleDurationContainers is not empty. If it is empty, I get a NoSuchElementException . How do I check this in the lambda expression? final List<ScheduleDurationContainer> bonusScheduleDurationContainers = scheduleDurationContainersOfWeek.stream() .filter(s -> s.getContainerType() == ScheduleIntervalContainerTypeEnum.BONUS) .collect(Collectors.toList()); final ScheduleDurationContainer bonusScheduleDurationContainer = bonusScheduleDurationContainers.stream() .filter(s -> s.getDayOfWeekStartingWithZero() == dayOfWeekTmp)