• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Iterator Vs Enumerator

 
AJ sisodia
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 14691
16
Eclipse IDE Ubuntu VI Editor
 
Jesper de Jong
Java Cowboy
Saloon Keeper
Posts: 15205
36
Android IntelliJ IDE Java Scala Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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):
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic