• 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

Iterators vs Enums

 
Greenhorn
Posts: 26
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I've asked this before elsewhere but didn't get any helpfull answers. Maybe John can help me out.
Are there any real benefits in replacing Enumerations with Iterators in existing code. The Collection type is vector (which was retrofitted into the collections Api). The Api docs strongly recommend moving from Enums to Collections but doesn't say why.
I am aware of the increased functionality that Iterator provides but am more interested in any performance/resource issues that would justify the change.
Best Wishes
Bill
 
Rancher
Posts: 13459
Android Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I can't answer the full question, but one reason to use Iterators over Enumerators is that Iterators have been inserted directly into the Collections framework.
My point is that it is possible to design a class specifying a List, Collection or other interface and not restrict the functionality to a single class (for example, rather than deciding to hard-code a Vector, you could specify that your code works with any class that implements the List interface)
Anyone who then uses your code is able to make their own decision on which class to use base on what is appropriate.
Dave.
[This message has been edited by David O'Meara (edited May 08, 2001).]
 
Author
Posts: 88
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
One benefit of using iterators over enumerations is iterators check for concurrent modifications when you access each element. If it is possible that the underlying collection can change while you are traversing the enumeration, the problem won't be caught. With iterator, it will be.
------------------
John Zukowski Author of "Definitive Guide to Swing for Java 2" and "Java Collections"
 
mister krabs
Posts: 13974
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Also Vectors are significantly slower than ArrayLists and LinkedLists.
Results of timed tests using different containers (from Thinking in Java):
Type Get Iteration Insert Remove
array 1430 3850 na na
ArrayList 3070 12200 500 46850
LinkedList 16320 9110 110 60
Vector 4890 16250 550 46850

[This message has been edited by Thomas Paul (edited May 08, 2001).]
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic