Tapas Bose Tapas Bose - 1 year ago 90
Java Question

Iterate an Enumeration in Java 8

Is it possible to iterate an

by using Lambda Expression? What will be the Lambda representation of the following code snippet:

Enumeration<NetworkInterface> nets = NetworkInterface.getNetworkInterfaces();

while (nets.hasMoreElements()) {
NetworkInterface networkInterface = nets.nextElement();


I didn't find any stream within it.

Answer Source

(Just because this answer is accepted by OP, it doesn't mean that it is the best one. I suggest reading other answers and picking one depending on situation you are in. Personally I find Hogler's answer nicest because of simplicity and no additional iteration - which happens in mine solution)

You can copy elements from your Enumeration to ArrayList with Collections.list and then use it like

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download