Java: use Enumeration multiple times

后端 未结 1 2010
悲哀的现实
悲哀的现实 2020-12-21 09:25

I work with DefaultMutableTreeNode, and it has methods depthFirstEnumeration(), breadthFirstEnumeration() and children()

相关标签:
1条回答
  • 2020-12-21 09:49

    No that is not possible with Enumeration. On this subject, java doc says:

    An object that implements the Enumeration interface generates a series of elements, one at a time.

    Notice the one at a time which means that if you want to manipulate the Enumeration as a list then you will have to convert it. You can create a List when you first request the Enumeration. This way you could use and manipulate it however you wish.

    Enumeration e = ...
    ArrayList aList = Collections.list(e);
    
    0 讨论(0)
提交回复
热议问题