Java Reference
In-Depth Information
Display 16.15
Methods in the ListIterator<T> Interface (part 2 of 2)
public T previous()
Returns the previous element of the list that produced the iterator. More specifically, returns the
element immediately before the cursor position.
Throws a NoSuchElementException if there is no previous element.
public boolean hasNext( )
Returns true if there is a suitable element for next() to return; returns false otherwise.
public boolean hasPrevious( )
Returns true if there is a suitable element for previous() to return; returns false otherwise.
public int nextIndex( )
Returns the index of the element that would be returned by a call to next() . Returns the list size
if the cursor position is at the end of the list.
public int previousIndex( )
Returns the index that would be returned by a call to previous() . Returns 1 if the cursor
position is at the beginning of the list.
public void add(T newElement) ( Optional )
Inserts newElement at the location of the iterator cursor (that is, before the value, if any, that
would be returned by next() and after the value, if any, that would be returned by previous() ).
Cannot be used if there has been a call to add or remove since the last call to next() or
previous() .
Throws IllegalStateException if neither next() nor previous() has been called, or if
the add or remove method has already been called after the last call to next() or previous() .
public void remove() ( Optional )
Removes from the collection the last element returned by next() or previous() .
This method can be called only once per call to next() or previous() .
Cannot be used if there has been a call to add or remove since the last call to next() or
previous() .
Throws IllegalStateException if neither next() nor previous() has been called, or if
the add or remove method has already been called after the last call to next() or previous() .
public void set( T newElement) ( Optional )
Replaces the last element returned by next() or previous() with newElement .
Cannot be used if there has been a call to add or remove since the last call to next() or
previous() .
Throws IllegalStateException if neither next() nor previous() has been called, or if
the add or remove method has been called since the last call to next() or previous() .
 
Search WWH ::




Custom Search