0

Hey guys,
what are advantages of external and internal iterators? I understand that internal allows you to add and remove nodes as it has implicit reference to data in the outer class? So, why would we need an external iterator? What are pros and cons of both?

2
Contributors
7
Replies
8
Views
7 Years
Discussion Span
Last Post by JamesCherrill
0

thanks, I have used listIterator before. What I am wondering is how would I implement it myself from scratch rather than one in java.util as an external class instead of having an inner iterator in my custom linked list.

0

Check the API for the Iterator interface. It's 3 methods (hasNext, next, remove). Just implement those in your class.

Edited by JamesCherrill: n/a

0

yeah i did that, but instead of doing that, i wanna have iterator as its own class and pass the list as a reference to iterate through.

0

Don't really understand why... but you can write a class that implements Iterator, and takes the list as a parameter to its constructor.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.