Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Treat Enumeration<T> as Iterator<T>

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?

like image 989
fredoverflow Avatar asked Feb 15 '11 17:02

fredoverflow


1 Answers

If you just want something to iterate over in a for-each loop (so an Iterable and not only an Iterator), there's always java.util.Collections.list(Enumeration<T> e) (without using any external libraries).

like image 88
David Avatar answered Sep 20 '22 13:09

David