• 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
  • Tim Cooke
  • paul wheaton
  • Paul Clapham
  • Ron McLeod
Sheriffs:
  • Jeanne Boyarsky
  • Liutauras Vilda
Saloon Keepers:
  • Tim Holloway
  • Carey Brown
  • Roland Mueller
  • Piet Souris
Bartenders:

Diff between Enumeration and Iterator

 
Ranch Hand
Posts: 486
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Enumeration is to generate series of elements. or collection of elements / objects into a single object.

Iterator is take place on Enumeration. it is to clear and remove elements/objects from Enumeration obj.

Can anyone explain these lines in pratical way and in easy way.
I am finding difficult to undertand.
pls
 
Ranch Hand
Posts: 35
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You are not allowed to remove elements from an Enumeration type in effect giving you a "view" only.

You can remove elements from an Iterator type thereby giving you "view & modify" behaviour.

This is from the javadocs :

NOTE: The functionality of this interface is duplicated by the Iterator interface. In addition, Iterator adds an optional remove operation, and has shorter method names. New implementations should consider using Iterator in preference to Enumeration.

 
Dinesh Tahiliani
Ranch Hand
Posts: 486
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
One more question,

I have heard that List and ArrayList only takes objects, whenever you want to add.
But according to new concept of generics it also takes integer, when i am performing addition to list or arraylist.
Can you please shed some lights on this.
:roll:
 
Ranch Hand
Posts: 108
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Actually when you add an integer to a List, its autowrapped as an Integer object and then added to the List.
 
Greenhorn
Posts: 26
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,
non-syncronized classes are using only iterator.
syncronized classes are using only Enumeration.

Regards,
D.Sitaramayya.
 
Rancher
Posts: 5184
84
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by d sitaramayya:
Hi,
non-syncronized classes are using only iterator.
syncronized classes are using only Enumeration.

Regards,
D.Sitaramayya.



That's not true. Vector is a synchronized class, and it has an iterator() method. It didn't originally have an iterator() method, but this was added back around JDK 1.2 when collections were brought into the main libraries. Now all collections have iterators, including Vector. Enumeration is just an older version of the same idea, with longer method names and one less method (remove()). So there's almost no reason to use Enumeration now.
 
Dinesh Tahiliani
Ranch Hand
Posts: 486
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Nad,

Actually when you add an integer to a List, its autowrapped as an Integer object and then added to the List



Can you explain me the above line with example. It would be really gerat for me.
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic