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?

Recommended Answers

All 7 Replies

how can u implement ext iterator?

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.

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

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.

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

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.