This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
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


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Iterator Vs Enumerator" Watch "Iterator Vs Enumerator" New topic
Author

Iterator Vs Enumerator

AJ sisodia
Greenhorn

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é
Sheriff

Joined: Nov 24, 2005
Posts: 14687
    
  16

http://www.coderanch.com/t/202139/Performance/java/Enumeration-vs-Iterator


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

Joined: Aug 16, 2005
Posts: 14074
    
  16

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 7 API documentation
Scala Notes - My blog about Scala
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Iterator Vs Enumerator
 
Similar Threads
HashMap vs Hashtable
Tutorial - Collections
Iterator can safely remove?
Effective Java: Avoiding API pitfalls
Iterators on HashMap