I have a custom, generic, singly LinkedList which I built myself. I can add, remove etc to the List just fine. I’d like to implement the Java ListIterator to my class. How would I go about starting this? What methods do I need to add to my class? All I can find on the web is examples of using the ListIterator on the default Java LinkedList which is no good to me. Thanks!
Share
You create a second class (usually a nested class of your linked list) that implements all the functions of the ListIterator interface. Note that some functions (like
addandremove) are optional—you can just throw an UnsupportedOperationException. Your linked list class needs to implement the methodslistIterator()andlistIterator(int)to return an instance of your second class.