Try Java, Catch the break.

Javaについての日々のあれこれ

Enumerationをラムダ(Lambda)でforEach

何てことない投稿です。

ResourceBundleからgetKeys()なんかするとEnumerationが返ってくるんですよね。
これをラムダ式でforEachまでもってくって話です。

EnumerationIteratorを使う

Apache commons-collectionsです。

new EnumerationIterator(bundle.getKeys()).forEachRemaining(key -> {
  // key;
});

Collections.listを使う

Java標準APIを使うならCollections.list()で一旦Listにします。

Collections.list(bundle.getKeys()).forEach(key -> {
  // key;
});