I have a class that implements the Enumeration<T> interface, but Java’s foreach loop requires the Iterator<T> interface. Is there an Enumeration to Iterator Adapter in Java’s standard library?
I have a class that implements the Enumeration<T> interface, but Java’s foreach loop requires
Share
You need a so called “Adapter”, to adapt the
Enumerationto the otherwise incompatibleIterator. Apache commons-collections hasEnumerationIterator. The usage is: