File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Beginning Java and the fly likes using a returned Enumeration Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "using a returned Enumeration" Watch "using a returned Enumeration" New topic
Author

using a returned Enumeration

Kevin Tysen
Ranch Hand

Joined: Oct 12, 2005
Posts: 255
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

Joined: Oct 27, 2005
Posts: 19680
    
  19

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:


SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6
How To Ask Questions How To Answer Questions
Kevin Tysen
Ranch Hand

Joined: Oct 12, 2005
Posts: 255
Thank you. I didn't know that you could just make an Enumeration object and use it like that.
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 38481
    
  23
Try to avoid using Enumeration; regard it as a legacy class. Most people would use Iterator instead.
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19680
    
  19

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.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: using a returned Enumeration