Forums Register Login

DIFFERENCE BETWEEN Enumeration and iterator?

+Pie Number of slices to send: Send
Can anyone explain me the difference between Enumeration and iterator?
+Pie Number of slices to send: Send
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.

 
+Pie Number of slices to send: Send
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.
You can't have everything. Where would you put it?
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com


reply
reply
This thread has been viewed 3023 times.
Similar Threads
Iterator & Enumeration
Iterator vs Enumeration
enumeration and iterator difference
diff betn iterator, enumeration and listIterator
iterator vs Enumeration
More...

All times above are in ranch (not your local) time.
The current ranch time is
Mar 18, 2024 21:15:13.