Treat Enumeration as Iterator

前端 未结 7 2398
感动是毒
感动是毒 2021-01-04 02:22

I have a class that implements the Enumeration interface, but Java\'s foreach loop requires the Iterator interface. Is there an <

7条回答
  •  佛祖请我去吃肉
    2021-01-04 02:57

    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 e) (without using any external libraries).

提交回复
热议问题