• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Iterator Vs Enumerator

 
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Sheriff
Posts: 14691
16
Eclipse IDE VI Editor Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
https://coderanch.com/t/202139/Performance/java/Enumeration-vs-Iterator
 
Java Cowboy
Posts: 16084
88
Android Scala IntelliJ IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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):
reply
    Bookmark Topic Watch Topic
  • New Topic