Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- {
- 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 :-("));
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement