iterator

Hi,To traverse through a collection object,we are using Iterator .why can't we use an Enumerator ?thks.
[132 byte] By [padikkathavana] at [2007-11-27 4:34:08]
# 1
I believe you can. The Enumerator came first, later the Iterator, which was considered (at least by some) an improvement. You can read more about both in the API docs.
OleVVa at 2007-7-12 9:44:02 > top of Java-index,Core,Core APIs...
# 2

Enumerations are deprecated, they were replaced by Iterator which duplicates Enumeration's functionality but has shorter method names (!) and also adds a remove() method. Some of the legacy Collections, Vector for instance, can still give you an Enumeration, but Iterators are flavour of the day. Why don't you want to use Iterator? If you've got client code that depends on Enumerations, you can write an adapter between the two.

georgemca at 2007-7-12 9:44:02 > top of Java-index,Core,Core APIs...
# 3

> I believe you can. The Enumerator came first, later

> the Iterator, which was considered (at least by some)

> an improvement. You can read more about both in the

> API docs.

Considered an improvement at least by some? Since Enumerations don't do anything Iterators don't, it's hard to see why anyone would prefer the former. Or was that just you safeguarding against the inevitable "I prefer Enumerations" that's marching toward this thread at some point :-)

georgemca at 2007-7-12 9:44:02 > top of Java-index,Core,Core APIs...
# 4

> Considered an improvement at least by some?

> Since Enumerations don't do anything Iterators don't,

> it's hard to see why anyone would prefer the former.

> Or was that just you safeguarding against the

> inevitable "I prefer Enumerations" that's marching

> toward this thread at some point :-)

I guess I was :-)

Where I go, there are regular arguments about the proper length of names, so I wouldn't be too sure.

Admitted, though, never having used an Enumeration myself, I wasn't sure about the exact differences. Glad you contributed it!

OleVVa at 2007-7-12 9:44:02 > top of Java-index,Core,Core APIs...
# 5

> > Considered an improvement at least by some?

> > Since Enumerations don't do anything Iterators

> don't,

> > it's hard to see why anyone would prefer the

> former.

> > Or was that just you safeguarding against the

> > inevitable "I prefer Enumerations" that's marching

> > toward this thread at some point :-)

>

> I guess I was :-)

> Where I go, there are regular arguments about the

> proper length of names, so I wouldn't be too sure.

> Admitted, though, never having used an Enumeration

> myself, I wasn't sure about the exact differences.

> Glad you contributed it!

Heh heh grumbly old beardie real ale developers no doubt! Seriously, is 'next' really so much more vague than 'nextElement'?

georgemca at 2007-7-12 9:44:02 > top of Java-index,Core,Core APIs...