File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Java in General and the fly likes why should i go for iterator get the data from collection Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "why should i go for iterator get the data from collection" Watch "why should i go for iterator get the data from collection" New topic
Author

why should i go for iterator get the data from collection

ramakrishna chowdary
Greenhorn

Joined: Feb 11, 2006
Posts: 6
Hi javaranch friends,

why should i go for iterator interface to navigate through the collection.

is it possible to write our own methods to fetch the data from the collection . if write what the problem we can face in collection.




Thanks®ards
rama krishna
Jeroen T Wenting
Ranch Hand

Joined: Apr 21, 2006
Posts: 1847
why should you NOT use something that's there as standard?

It works, and works well. There's no reason to reinvent the wheel.


42
Deepak Bala
Bartender

Joined: Feb 24, 2006
Posts: 6657
    
    5

What do you have against an Iterator ?


SCJP 6 articles - SCJP 5/6 mock exams - More SCJP Mocks
Henry Wong
author
Sheriff

Joined: Sep 28, 2004
Posts: 18101
    
  39

why should i go for iterator interface to navigate through the collection.


The main advantage in using an iterator is that it abstracts the collection. Your code is not concerned with the type of collection, nor how is it implemented, you merely use it. And assume that the iterator is written to best traverse the collection -- regardless of whether it is a List or a Set, or whether it is implemented as an array, hashed, or linked.

Henry


Books: Java Threads, 3rd Edition, Jini in a Nutshell, and Java Gems (contributor)
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: why should i go for iterator get the data from collection
 
Similar Threads
For each loop
style issue(maybe performance, too)
Understanding the Manipulation of the Relationship
Iterators on HashMap
Iterator instantiation