* An iterator for lists that allows the programmer
* to traverse the list in either direction, modify
* the list during iteration, and obtain the iterator's
* current position in the list. A {@code ListIterator}
* has no current element; its <I>cursor position</I> always
* lies between the element that would be returned by a call
* to {@code previous()} and the element that would be
* returned by a call to {@code next()}.
列表的迭代器,允许沿任一方向遍历列表,在迭代过程中修改列表并获取迭代器在列表中的当前位置。
ListIterator没有当前元素; 其光标位置始终位于调用next()返回的元素和调用next()返回的元素之间。
* An iterator for a list of length {@code n} has {@code n+1} possible
* cursor positions, as illustrated by the carets ({@code ^}) below:
* <PRE>
* Element(0) Element(1) Element(2) ... Element(n-1)
* cursor positions: ^ ^ ^ ^ ^
* </PRE>
* Note that the {@link #remove} and {@link #set(Object)} methods are
* <i>not</i> defined in terms of the cursor position; they are defined to
* operate on the last element returned by a call to {@link #next} or
* {@link #previous()}.
remove()和#set(Object)方法不是根据光标位置来定义的。
它们被定义为对调用next()或previous()返回的最后一个元素进行操作。
源码本体:
继承Iterator接口
public interface ListIterator<E> extends Iterator<E> {
// Query Operations
查询方法
boolean hasNext();
E next();
boolean hasPrevious();
E previous();
int nextIndex();
int previousIndex();
// Modification Operations
修改操作
void remove();
void set(E e);
void add(E e);
}