Andy Jack wrote:I was looking at the Java code for some iterators. I am not sure if this is something I should know well. Is it okay if I know only what an iterator can do for me and how to use it ?
Thanks
Yes it is ok. Until an interviewer asks you how to implement one
Most interviewers will not ask you how the internals of any system / utility class works. However it is always nice to know. Iterators have several interesting properties to explore.
1. How do you make sure iterators work properly when used across threads. Should you care ?
2. Does the immutability of a data structure affect how iterators behave ?
3. When should an iterator throw ConcurrentModificationExceptions ?
4. How do system classes know that the data structure that the iterator is operating on has changed ?
5. How can you make any arbitrary class function inside a for-each loop ?
and so on...
Explore several iterators before saying you know how to implement one. Try implementing an iterator to
boost your confidence.