Overview | Package | Class | Tree | Index | Help
PREV CLASS | NEXT CLASS FRAMES  | NO FRAMES
SUMMARY:  INNER | FIELD | CONSTR | METHOD DETAIL:  FIELD | CONSTR | METHOD

Interface java.util.ListIterator


public abstract interface ListIterator
extends Iterator
An Iterator for Lists that allows the programmer to traverse the List in either direction and modify the list during iteration.

Since:
JDK1.2
Version:
1.8 03/26/98
See Also:
Collection, List, Iterator, Enumeration

Method Summary
void add(java.lang.Object o)
          Inserts the specified element into the List.
boolean hasNext()
          Returns true if this ListIterator has more elements when traversing the List in the forward direction.
boolean hasPrevious()
          Returns true if this ListIterator has more elements when traversing the list in the reverse direction.
int nextIndex()
          Returns the index of the element that would be returned by a subsequent call to next.
java.lang.Object next()
          Returns the next element in the List.
int previousIndex()
          Returns the index of the element that would be returned by a subsequent call to previous.
java.lang.Object previous()
          Returns the previous element in the List.
void remove()
          Removes from the List the last element that was returned by next or previous.
void set(java.lang.Object o)
          Replaces the last element returned by next or previous with the specified element.
 

Method Detail

hasNext

public 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.)
Specified by:
hasNext in interface Iterator
Returns:
true if the ListIterator has more elements when traversing List in the forward direction.

next

public java.lang.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.)
Specified by:
next in interface Iterator
Returns:
the next element in the List.
Throws:
NoSuchElementException - iteration has no next element.

hasPrevious

public 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.)
Returns:
true if the ListIterator has more elements when traversing List in the reverse direction.

previous

public java.lang.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.)
Returns:
the previous element in the List.
Throws:
NoSuchElementException - 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 ListIterator is at the end of the list.)
Returns:
the index of the element that would be returned by a subsequent call to next, or List size if ListIterator is at end of List.

previousIndex

public 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.)
Returns:
the index of the element that would be returned by a subsequent call to previous, or -1 if ListIterator is at beginning of List.

remove

public 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.
Specified by:
remove in interface Iterator
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 void set(java.lang.Object 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.
ClassCastException - class of the specified element prevents it from being added to this List.
java.lang.IllegalArgumentException - some aspect of the specified element prevents it from being added to this List.
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 void add(java.lang.Object 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.
ClassCastException - class of the specified element prevents it from being added to this Set.
java.lang.IllegalArgumentException - some aspect of this element prevents it from being added to this Collection.

Overview | Package | Class | Tree | Index | Help
PREV CLASS | NEXT CLASS FRAMES  | NO FRAMES
SUMMARY:  INNER | FIELD | CONSTR | METHOD DETAIL:  FIELD | CONSTR | METHOD