• 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

Collection/Iterator

 
Ranch Hand
Posts: 75
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,
What's the best way to iterate thru a collection(say a Vector)?
Should I get the Iterator for this Vector, and use it as in the following?
Vector someVector = new Vector();
//code to populate the vector
Iterator iter = someVector.iterator();
while (iter.hasNext())
{
Object obj = iter.next();
//do Some thing with the Object
}
Or is it better to avoid the iterator and use the Vector directly as follows?
for(int i=0; i< someVector.size(); i++)
{
Object obj = someVector.elementAt(i);
}
Any help in this regard would be appreciated.
 
Ranch Hand
Posts: 3143
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
see this thread http://www.javaranch.com/ubb/Forum33/HTML/001228.html we were just discussing this!
[This message has been edited by Angela Poynton (edited January 05, 2001).]
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic