Java 8 way to work with an enum [closed]

I’d go for EnumSet. Because forEach() is also defined on Iterable, you can avoid creating the stream altogether:

EnumSet.allOf(Letter.class).forEach(x -> foo(x));

Or with a method reference:

EnumSet.allOf(Letter.class).forEach(this::foo);

Still, the oldschool for-loop feels a bit simpler:

for (Letter x : Letter.values()) {
    foo(x);
}

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)