java.util.ListIterator翻译

 
JavaTM 2 Platform
Std. Ed. v1.4.2

java.util
Interface ListIterator

All Superinterfaces:
Iterator

public interface ListIterator extends Iterator

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 ListIterator has no current element; its cursor position always lies between the element that would be returned by a call to previous() and the element that would be returned by a call to next(). In a list of length n, there are n+1 valid index values, from 0 to n, inclusive. 列表的迭代器允许程序员以不同方向遍历列表,遍历中修改列表,获得列表中迭代器的当前位置。 ListIterator没有当前元素,光标位置总是位于调用previous()返回的元素和 调用next()返回的元素之间。在长度为n的列表中,有n+1个有效下标值。 包括从0到n。

          Element(0)   Element(1)   Element(2)   ... Element(n)   
        ^            ^            ^            ^               ^
 Index: 0            1            2            3               n+1

 

Note that the remove() and set(Object) methods are not defined in terms of the cursor position; they are defined to operate on the last element returned by a call to next() or previous(). 注意remove()和set(Object)方法没有定义为和光标位置相关,它们 定义为操作调用next()或previous()后返回的元素。

This interface is a member of the Java Collections Framework. 该接口是Java集合框架的成员之一。

Since:
1.2
See Also:
Collection , List , Iterator , Enumeration

Method Summary
 voidadd(Object o)
          Inserts the specified element into the list (optional operation). 向列表插入指定元素(可选操作)。
 booleanhasNext()
          Returns true if this list iterator has more elements when traversing the list in the forward direction. 正向遍历列表时,如果列表迭代器还有元素,返回true。
 booleanhasPrevious()
          Returns true if this list iterator has more elements when traversing the list in the reverse direction. 逆向遍历列表时,如果列表迭代器还有元素,返回true。
 Objectnext()
          Returns the next element in the list. 返回列表的下一个元素。
 intnextIndex()
          Returns the index of the element that would be returned by a subsequent call to next. 返回接下去调用next所返回元素的下标。
 Objectprevious()
          Returns the previous element in the list. 返回列表的前一个元素。
 intpreviousIndex()
          Returns the index of the element that would be returned by a subsequent call to previous. 返回接下去调用previous所返回元素的下标。
 voidremove()
          Removes from the list the last element that was returned by next or previous (optional operation). 从列表中删除next或previous返回的元素(可选操作)。
 voidset(Object o)
          Replaces the last element returned by next or previous with the specified element (optional operation). 用指定元素替换next或previous返回的元素(可选操作)。
 

Method Detail

hasNext

public boolean hasNext()
Returns true if this list iterator has more elements when traversing the list in the forward direction. (In other words, returns true if next would return an element rather than throwing an exception.) 正向遍历列表时,如果列表迭代器还有元素,返回true。(换句话说,如果next返回一个元素而不是抛出异常, 返回true。)

Specified by:
hasNext in interface Iterator
Returns:
true if the list iterator has more elements when traversing the list in the forward direction. 正向遍历列表时,如果列表迭代器还有元素,返回true。

next

public Object next()
Returns the next element in the list. This method may be called repeatedly to iterate through the list, or intermixed with calls to previous to go back and forth. (Note that alternating calls to next and previous will return the same element repeatedly.) 返回列表的下一个元素。该方法可能重复调用以遍历列表,或者和previous 联合调用来向后或向前。(注意交替调用next和previous将重复返回相同的元素。)

Specified by:
next in interface Iterator
Returns:
the next element in the list. 列表的下一个元素。
Throws:
NoSuchElementException - if the iteration has no next element. 如果迭代中没有下一个元素抛出。

hasPrevious

public boolean hasPrevious()
Returns true if this list iterator has more elements when traversing the list in the reverse direction. (In other words, returns true if previous would return an element rather than throwing an exception.) 逆向遍历列表时,如果列表迭代器还有元素,返回true。(换句话说,如果previous返回一个元素而不是抛出异常, 返回true。)

Returns:
true if the list iterator has more elements when traversing the list in the reverse direction. 逆向遍历列表时,如果列表迭代器还有元素,返回true。

previous

public Object previous()
Returns the previous element in the list. This method may be called repeatedly to iterate through the list backwards, or intermixed with calls to next to go back and forth. (Note that alternating calls to next and previous will return the same element repeatedly.) 返回列表的前一个元素。该方法可能重复调用以向后遍历列表,或者和next 联合调用来向后或向前。(注意交替调用next和previous将重复返回相同的元素。)

Returns:
the previous element in the list. 列表的前一个元素。
Throws:
NoSuchElementException - if the iteration has no previous element. 如果迭代中没有前一个元素抛出。

nextIndex

public int nextIndex()
Returns the index of the element that would be returned by a subsequent call to next. (Returns list size if the list iterator is at the end of the list.) 返回接下去调用next所返回元素的下标。(如果列表迭代器已位于列表末尾,返回列表大小。)

Returns:
the index of the element that would be returned by a subsequent call to next, or list size if list iterator is at end of list. 接下去调用next所返回元素的下标,如果列表迭代器已位于列表末尾,返回列表大小。

previousIndex

public int previousIndex()
Returns the index of the element that would be returned by a subsequent call to previous. (Returns -1 if the list iterator is at the beginning of the list.) 返回接下去调用previous所返回元素的下标。(如果列表迭代器已位于列表起始,返回-1。)

Returns:
the index of the element that would be returned by a subsequent call to previous, or -1 if list iterator is at beginning of list. 接下去调用previous所返回元素的下标,如果列表迭代器已位于列表起始,返回-1。

remove

public void remove()
Removes from the list the last element that was returned by next or previous (optional operation). This call can only be made once per call to next or previous. It can be made only if ListIterator.add has not been called after the last call to next or previous. 从列表中删除next或previous返回的元素(可选操作)。该调用只能在每次调用 next或者previous后执行一次。而且只能在调用next或previous后而没有调用 ListIterator.add前执行。

Specified by:
remove in interface Iterator
Throws:
UnsupportedOperationException - if the remove operation is not supported by this list iterator. 如果列表迭代器不支持remove操作时抛出。
IllegalStateException - neither next nor previous have been called, or remove or add have been called after the last call to * next or previous. 如果next和previous还没被调用或者在调用next或previous之后调用了remove或add抛出。

set

public void set(Object o)
Replaces the last element returned by next or previous with the specified element (optional operation). This call can be made only if neither ListIterator.remove nor ListIterator.add have been called after the last call to next or previous. 用指定元素替换next或previous返回的元素(可选操作)。该调用只能在 调用next或previous后而没有调用ListIterator.remove和ListIterator.add前执行。

Parameters:
o - the element with which to replace the last element returned by next or previous. 替换由next或previous返回元素的元素。
Throws:
UnsupportedOperationException - if the set operation is not supported by this list iterator. 如果列表迭代器不支持set操作时抛出。
ClassCastException - if the class of the specified element prevents it from being added to this list. 如果指定元素的类型不允许其加入列表时抛出。
IllegalArgumentException - if some aspect of the specified element prevents it from being added to this list. 如果指定元素的某些方面不允许其加入列表时抛出。
IllegalStateException - if neither next nor previous have been called, or remove or add have been called after the last call to next or previous. 如果next和previous还没被调用或者在调用next或previous之后调用了remove或add抛出。

add

public void add(Object o)
Inserts the specified element into the list (optional operation). The element is inserted immediately before the next element that would be returned by next, if any, and after the next element that would be returned by previous, if any. (If the list contains no elements, the new element becomes the sole element on the list.) The new element is inserted before the implicit cursor: a subsequent call to next would be unaffected, and a subsequent call to previous would return the new element. (This call increases by one the value that would be returned by a call to nextIndex or previousIndex.) 向列表插入指定元素(可选操作)。元素被插入在调用next返回的元素之前或者 调用previous返回的元素之后。(如果列表不包含元素,那么新元素成了列表中唯一的元素。) 新元素插入隐式光标之前:随后调用next没有效用,调用previous将返回新元素。 (该调用将使调用nextIndex或previousIndex的返回值加1。)

Parameters:
o - the element to insert. 要插入的元素。
Throws:
UnsupportedOperationException - if the add method is not supported by this list iterator. 如果列表迭代器不支持add操作时抛出。
ClassCastException - if the class of the specified element prevents it from being added to this list. 如果指定元素的类型不允许其加入列表时抛出。
IllegalArgumentException - if some aspect of this element prevents it from being added to this list. 如果指定元素的某些方面不允许其加入列表时抛出。

JavaTM 2 Platform
Std. Ed. v1.4.2

Submit a bug or feature
For further API reference and developer documentation, see Java 2 SDK SE Developer Documentation . That documentation contains more detailed, developer-targeted descriptions, with conceptual overviews, definitions of terms, workarounds, and working code examples.

Copyright 2003 Sun Microsystems, Inc. All rights reserved. Use is subject to license terms. Also see the documentation redistribution policy.

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值