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