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

DIFFERENCE BETWEEN Enumeration and iterator?

niisha guupta
Greenhorn

Joined: Dec 26, 2008
Posts: 6
Can anyone explain me the difference between Enumeration and iterator?
Christophe Verré
Sheriff

Joined: Nov 24, 2005
Posts: 14687
    
  16

Enumeration is an old twig from Java1.0. About the difference betweem Enumeration and Iterator, here is what the Enumeration API tells us :
API wrote:
The functionality of this interface is duplicated by the Iterator interface. In addition, Iterator adds an optional remove operation, and has shorter method names. New implementations should consider using Iterator in preference to Enumeration.


[My Blog]
All roads lead to JavaRanch
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19684
    
  20

Like Christophe said, an Iterator can do the same an Enumeration can do, with added optional removal of elements. In fact, you can implement one backed by the other:

Note that the remove() method throws an UnsupportedOperationException; this is done a lot when an interface defines an optional method and you wish not to really implement it. You must provide an implementation though because the interface still defines the method, so throwing this exception is the best implementation.


SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6
How To Ask Questions How To Answer Questions
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: DIFFERENCE BETWEEN Enumeration and iterator?