Meaningless Drivel is fun!
The moose likes Beginning Java and the fly likes Iterator Vs Enumerator Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Iterator Vs Enumerator" Watch "Iterator Vs Enumerator" New topic

Iterator Vs Enumerator

AJ sisodia

Joined: Jan 19, 2005
Posts: 16
I take it both serve the same purpose.
Enumeration interface has become obsolete but in case of HashTable enumerator would be preferred as HashTable does not directly support itertors.

i would like to know can i altogether leave enumerator and can depend on iterator to access elements one by one.
Why do we give preference to iterator over enumerator. What is the difference between the two if any.
Christophe Verré

Joined: Nov 24, 2005
Posts: 14688

[My Blog]
All roads lead to JavaRanch
Jesper de Jong
Java Cowboy
Saloon Keeper

Joined: Aug 16, 2005
Posts: 15084

It's Hashtable (lower case t), not HashTable.

You should use HashMap instead of Hashtable, if possible. Hashtable is obsolete, just like interface Enumeration.

If you are stuck with Hashtable and you want to use an iterator, you can easily write an adapter class that adapts an Enumeration to an Iterator (note, this is untested code):

Java Beginners FAQ - JavaRanch SCJP FAQ - The Java Tutorial - Java SE 8 API documentation
I agree. Here's the link:
subject: Iterator Vs Enumerator
It's not a secret anymore!