Win a copy of Escape Velocity: Better Metrics for Agile Teams this week in the Agile and Other Processes forum!
  • 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
  • Liutauras Vilda
  • Tim Cooke
  • Paul Clapham
  • Jeanne Boyarsky
Sheriffs:
  • Ron McLeod
  • Frank Carver
  • Junilu Lacar
Saloon Keepers:
  • Stephan van Hulst
  • Tim Moores
  • Tim Holloway
  • Al Hobbs
  • Carey Brown
Bartenders:
  • Piet Souris
  • Frits Walraven
  • fred rosenberger

Collection API

 
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hai friends
can anyone help me understanding the difference between Enumuration and Iterator?

 
Ranch Hand
Posts: 1710
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Enumeration and Iterator gives you almost same facility.

What Ivor Horton author of Beginning Java 2 says in his book regarding that:


An enumerator provides essentially the same capability as an iterator, but it
is recommended in the Java documentation that you use an iterator in
preference to an enumerator for collections. There is nothing particularly
wrong with enumerator- it's just that Iterator<> interface declares and
optional remove() method that the Enumeration<> interface does not, and the
methods in the Iterator<> interface have shorter names than those in the Enumeration<> interface, so code that uses them will be less cluttered.




Thanks,
 
Ranch Hand
Posts: 60
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Enumeration and Iterator are both interfaces.
Enumeration is a legacy interface and is more
generalized, you may find it anywhere in the
entire api. Though it is commonly used with
the legacy classes like the Vector and Hashtable
it is also used independent of them also. eg.
StringTokenizer.
Iterator on the other hand is always used with
a Collection, it always has an underlying Collection
on which it operates. Also Iterator has an additional
functionality which allows removal of element from
the underlying Collection.
 
Ranch Hand
Posts: 7729
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
If you really, really need an Enumeration for a Collection you can use the static method Collections.enumerator to give you one. The Enumeration is dead, long live Enumerations!
 
It looks like it's time for me to write you a reality check! Or maybe a tiny ad!
Garden Master Course kickstarter
https://coderanch.com/t/754577/Garden-Master-kickstarter
reply
    Bookmark Topic Watch Topic
  • New Topic