dcsimg
Usage of iterator and for loop while retrieving values from an ArrayList
2 posts in topic
Flat View  Flat View
TOPIC ACTIONS:
 

Posted By:   Jeetendra_Ramchand
Posted On:   Monday, March 15, 2004 11:53 PM

Values from an iterator can be retrieved using an Iterator or a for loop. Can anyone please point out the difference in their usage like advantages or disadvantages?

Re: Usage of iterator and for loop while retrieving values from an ArrayList

Posted By:   Sachin_Gandhe  
Posted On:   Friday, April 16, 2004 05:09 AM

I think the best way to iterate thr. is not by using
iterators or any iterator provided functions.Best way
would be to get the total size in a variable and then
using that we can iterate thr. using for loop or while
loop.This appoach possible minimzes the unecessary
function calls which affects the performance.

Re: Usage of iterator and for loop while retrieving values from an ArrayList

Posted By:   Simon_Ablett  
Posted On:   Tuesday, March 16, 2004 04:01 AM

An iterator is simply a class that is able to remember a position in a data collection object. Its usage is as follows (assume that 'Route.getAllRoutes' returns a 'Vector' of 'String' objects).


Vector routes = Route.getAllRoutes();
Iterator routeIter = routes.iterator();
while(routeIter.hasNext()==true)
{
String routName = (String) routeIter.next());
}
}

Regards.
About | Sitemap | Contact