Win a copy of Learn Spring Security (video course) this week in the Spring forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

using a returned Enumeration

 
Kevin Tysen
Ranch Hand
Posts: 255
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The DefaultMutableTreeNode object has a few methods which return an Enumeration. But how do you use the Enumeration which you get?
Do you do this?
Enumeration enumer = myDefaultMutableTreeNode.getChildren();
I have a feeling that will not work.
 
Rob Spoor
Sheriff
Pie
Posts: 20492
54
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Do you know how to use an Iterator? An Enumeration works quite similar.

There are two often used ways, one with a while loop and one with a for loop:
 
Kevin Tysen
Ranch Hand
Posts: 255
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you. I didn't know that you could just make an Enumeration object and use it like that.
 
Campbell Ritchie
Sheriff
Posts: 48363
56
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Try to avoid using Enumeration; regard it as a legacy class. Most people would use Iterator instead.
 
Rob Spoor
Sheriff
Pie
Posts: 20492
54
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
True, but some older classes still return them (ZipFile is one of them), and you do need to know how to handle them. Also, Iterator and Enumeration are very very similar; the only reason Iterator is preferred is the (optional) remove method, and the shorter method names.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic