{ boolean doElse = true; for (final Foo foo : this.getFoos()) { // process the foo doElse = false; } if (doElse) { // There was not a single foo } } // ---------------------------------------- // How it would be with for-else: for (final Foo foo : this.getFoos()) { // process the foo } else { // There was not a single foo } // ----------------------------------------- // Java 8 Stream API: getFoos().stream().forEachElse(f -> f.process(), () -> System.out.println("No foo :-("));