cle tan wrote:not sure how to use implement it in a class though
Ah, now
that is a different question. What do you want to implement it for?
Just FYI, the implementation must:
Return the "first" element the first time next() is called (whatever that is), or throw an Exception if there isn't one.thereafter, return the "next" element (whatever that means) every time next() is called, or throw an Exception if there isn't one.Return true the first time hasNext() is called, unless there are no elements to iterate.thereafter, return true every time hasNext() is called, providing a subsequent call to next() will return an element and NOT throw an Exception; otherwise false.remove() the element returned by the last next() call. Personally, I usually find it easier to have it simply throw UnsupportedOperationException, because the method is optional and sometimes subtle.
It's worth reading the API documentation, because it has useful pointers (particularly for ListIterator).
And yes, it's not straightforward, and it's not meant to be. But once you've written half a dozen or so, you'll start to recognise
patterns in how to implement.
Winston