dcsimg
Return Iterator or Collection?
0 posts in topic
Flat View  Flat View
TOPIC ACTIONS:
 

Posted By:   roy_ngan
Posted On:   Wednesday, April 3, 2002 11:58 PM

When deciding the return value of an API, someone will decide to return Iterator if the result is a list of object. But I don't understand the advantage of returning Iterator. The caller of the API can just only iterate the result list once. And it cannot further process the result list, unless it creates its own List to store the elements.


I think a better way is returning a java.util.Collection. The caller can be more flexible in using the result list. Is there any advantage for returning Iterator instead of a Collection?


Roy

About | Sitemap | Contact