Chapter 12 also talks about the Iterator interface. Iterators are a bit clumsier than using the 'foreach' (for (Type item: Collection) form), but they have the advantage that you can remove elements from the collection while iterating over it. The video below shows you how to use them:
The video below is a longer example showing how one might implement the Iterator interface in a class.
Finally, the next one shows you how to build your own generic class.
No comments:
Post a Comment