• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

why should i go for iterator get the data from collection

 
ramakrishna chowdary
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 1847
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
why should you NOT use something that's there as standard?

It works, and works well. There's no reason to reinvent the wheel.
 
Deepak Bala
Bartender
Posts: 6663
5
Firefox Browser Linux MyEclipse IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What do you have against an Iterator ?
 
Henry Wong
author
Marshal
Pie
Posts: 21435
84
C++ Chrome Eclipse IDE Firefox Browser Java jQuery Linux VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic