Java: Enumeration from Set<String>

well actually picture well actually · Aug 17, 2011 · Viewed 44.8k times · Source

I have a simple collections question. I have a Set<String> object. I want an Enumeration<String> of the Strings in that Set. I need an Enumeration<String> since I am overriding a method that specifically returns an Enumeration<String>. What is the cleanest/best way to go about it?

Answer

Kevin Bourrillion picture Kevin Bourrillion · Aug 19, 2011

java.util.Collections.enumeration(set)

Javadoc

Returns an enumeration over the specified collection. This provides interoperability with legacy APIs that require an enumeration as input.