The List
interface has two methods listIterator()
and iterator()
. why both of these are needed.
From the docs:
Iterator<E> iterator()
Returns an iterator over the elements in this list in proper sequence.
ListIterator<E> listIterator()
Returns a list iterator over the elements in this list (in proper sequence).
ListIterator<E> listIterator(int index)
Returns a list iterator over the elements in this list (in proper sequence), starting at the
specified position in the list. The specified index indicates the first element that would be
returned by an initial call to next. An initial call to previous would return the element with the
specified index minus one.
so basically, ListIterator()
has this additional methods to get previous and next
elements while Iterator()
has only next
elements. Is this only for this purpose, there is another ListIterator() interface
and listiterator() method in List inteface