iterator和listIterator()有什么区别?

Pri*_*shi 1 java iterator list

可能重复:
Iterator和Listiterator之间的区别?

最近,当我通过javadocs goint时,我在List接口中找到了两个方法:iterator()listIterator().除了不同的返回类型,这两种方法之间的其他差异是什么?以下是两种方法的java文档.

// List Iterators
/**
 * Returns a list iterator over the elements in this list (in proper
 * sequence).
 *
 * @return a list iterator over the elements in this list (in proper
 *         sequence)
 */
ListIterator<E> listIterator();
Run Code Online (Sandbox Code Playgroud)

/**
 * Returns an iterator over the elements in this list in proper sequence.
 *
 * @return an iterator over the elements in this list in proper sequence
 */
Iterator<E> iterator();
Run Code Online (Sandbox Code Playgroud)

Mat*_*ows 6

ListIterator是一个扩展Iterator的子类.

的ListIterator允许穿越在两个方向上,而不是如果有更多的元素(只检查hasNext()),并获得下一个(next()).它保持光标位置并调用next()previous()改变位置并返回相关值. ListIterator还允许add(E e)条目的addition()和条目(set(E e))到基础列表的设置(与Iterator不同,它只允许删除).