[all packages] [package java.util] [class hierarchy] [index]

public interface java.util.ListIterator<A>

(source file: ListIterator.java)
java.lang.Object
   |
   +----java.util.ListIterator<A>

The pure class interface.
public interface ListIterator<A>
  implements Iterator<A>
An Iterator for Lists that allows the programmer to traverse the List in either direction and modify the list during iteration.

See also:
Collection, List, Iterator, Enumeration

Methods

O add(A)
Inserts the specified element into the List
O hasNext()
Returns true if this ListIterator has more elements when traversing the list in the
O hasPrevious()
Returns true if this ListIterator has more elements when traversing the list in the
O next()
Returns the next element in the List
O nextIndex()
Returns the index of the element that would be returned by a subsequent call to next
O previous()
Returns the previous element in the List
O previousIndex()
Returns the index of the element that would be returned by a subsequent call to previous
O remove()
Removes from the List the last element that was returned by next or previous
O set(A)
Replaces the last element returned by next or previous with the specified element

Methods

O hasNext
public abstract boolean hasNext();
Returns true if this ListIterator 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.)

O next

public abstract A 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.)

Throws:
NoSuchElementException -iteration has no next element.

O hasPrevious

public abstract boolean hasPrevious();
Returns true if this ListIterator 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.)

O previous

public abstract A 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.)

Throws:
NoSuchElementException -iteration has no previous element.

O nextIndex

public abstract int nextIndex();
Returns the index of the element that would be returned by a subsequent call to next. (Returns List size if the ListIterator is at the end of the list.)

O previousIndex

public abstract int previousIndex();
Returns the index of the element that would be returned by a subsequent call to previous. (Returns -1 if the ListIterator is at the beginning of the list.)

O remove

public abstract void remove();
Removes from the List the last element that was returned by next or previous. 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. Optional operation.

Throws:
UnsupportedOperationException -remove is not supported by this ListIterator.
IllegalStateException -neither next nor previous have been called, or remove or add have been called after the last call to next or previous.

O set

public abstract void set(A o);
Replaces the last element returned by next or previous with the specified element. This call can be made only if neither ListIterator.remove nor ListIterator.add have been called after the last call to next or previous. Optional operation.

Throws:
UnsupportedOperationException -set is not supported by this ListIterator.
IllegalStateException -neither next nor previous have been called, or remove or add have been called after the last call to next or previous.

O add

public abstract void add(A o);
Inserts the specified element into the List. The element is inserted immediately before the next element that would be returned by getNext, if any, and after the next element that would be returned by getPrevious, if any. (If the List contains no elements, the new element becomes the sole element on the List.) This call does not move the cursor: a subsequent call to next would return the element that was added by the call, and a subsequent call to previous would be unaffected. Optional operation.

Throws:
UnsupportedOperationException -add is not supported by this ListIterator.


[all packages] [package java.util] [class hierarchy] [index]
java.util.ListIterator.html