Skip to content
Advertisement

Iterate an Enumeration in Java 8

Is it possible to iterate an Enumeration by using Lambda Expression? What will be the Lambda representation of the following code snippet:

JavaScript

I didn’t find any stream within it.

Advertisement

Answer

In case you don’t like the fact that Collections.list(Enumeration) copies the entire contents into a (temporary) list before the iteration starts, you can help yourself out with a simple utility method:

JavaScript

Then you can simply do forEachRemaining(enumeration, lambda-expression); (mind the import static feature)…

User contributions licensed under: CC BY-SA
10 People found this is helpful
Advertisement