generic Enumeration to Iterable converter

IAdapter picture IAdapter · Nov 19, 2011 · Viewed 15.5k times · Source

HttpServletRequest is using a lot of java.util.Enumeration. I would like to use them in for-each, so i need to convert them into interable. this is not a problem, but I since I have more than one project needing this I need a library to do this. I would rather not make my own - is there any standard library that supports this kind of decoration?

Is there a built-in construct to convert an Enumeration to an Iterable?

Answer

skaffman picture skaffman · Nov 19, 2011

java.util.Collections has a list method that copies an Enumeration into a List, which you can then use in a for-each loop (see javadoc).