该List
接口有两个方法listIterator()
和iterator()
. 为什么这两个都需要。
从文档:
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.
所以基本上,ListIterator()
有这个额外的方法来获取previous and next
元素,而Iterator()
只有next
元素。难道这只是为了这个目的,还有另一个ListIterator() interface
和listiterator() method in List inteface