Skip to content

Most visited

Recently visited

navigation
Added in API level 1

ListIterator

public interface ListIterator
implements Iterator<E>

java.util.ListIterator<E>


An ListIterator is used to sequence over a List of objects. ListIterator can move backwards or forwards through the list.

Summary

Public methods

abstract void add(E object)

Inserts the specified object into the list between next and previous.

abstract boolean hasNext()

Returns whether there are more elements to iterate.

abstract boolean hasPrevious()

Returns whether there are previous elements to iterate.

abstract E next()

Returns the next object in the iteration.

abstract int nextIndex()

Returns the index of the next object in the iteration.

abstract E previous()

Returns the previous object in the iteration.

abstract int previousIndex()

Returns the index of the previous object in the iteration.

abstract void remove()

Removes the last object returned by next or previous from the list.

abstract void set(E object)

Replaces the last object returned by next or previous with the specified object.

Inherited methods

From interface java.util.Iterator

Public methods

add

Added in API level 1
void add (E object)

Inserts the specified object into the list between next and previous. The object inserted will be the previous object.

Parameters
object E: the object to insert.
Throws
UnsupportedOperationException if adding is not supported by the list being iterated.
ClassCastException if the class of the object is inappropriate for the list.
IllegalArgumentException if the object cannot be added to the list.

hasNext

Added in API level 1
boolean hasNext ()

Returns whether there are more elements to iterate.

Returns
boolean true if there are more elements, false otherwise.

See also:

hasPrevious

Added in API level 1
boolean hasPrevious ()

Returns whether there are previous elements to iterate.

Returns
boolean true if there are previous elements, false otherwise.

See also:

next

Added in API level 1
E next ()

Returns the next object in the iteration.

Returns
E the next object.
Throws
NoSuchElementException if there are no more elements.

See also:

nextIndex

Added in API level 1
int nextIndex ()

Returns the index of the next object in the iteration.

Returns
int the index of the next object, or the size of the list if the iterator is at the end.
Throws
NoSuchElementException if there are no more elements.

See also:

previous

Added in API level 1
E previous ()

Returns the previous object in the iteration.

Returns
E the previous object.
Throws
NoSuchElementException if there are no previous elements.

See also:

previousIndex

Added in API level 1
int previousIndex ()

Returns the index of the previous object in the iteration.

Returns
int the index of the previous object, or -1 if the iterator is at the beginning.
Throws
NoSuchElementException if there are no previous elements.

See also:

remove

Added in API level 1
void remove ()

Removes the last object returned by next or previous from the list.

Throws
UnsupportedOperationException if removing is not supported by the list being iterated.
IllegalStateException if next or previous have not been called, or remove or add have already been called after the last call to next or previous.

set

Added in API level 1
void set (E object)

Replaces the last object returned by next or previous with the specified object.

Parameters
object E: the object to set.
Throws
UnsupportedOperationException if setting is not supported by the list being iterated
ClassCastException if the class of the object is inappropriate for the list.
IllegalArgumentException if the object cannot be added to the list.
IllegalStateException if next or previous have not been called, or remove or add have already been called after the last call to next or previous.
This site uses cookies to store your preferences for site-specific language and display options.

Hooray!

This class requires API level or higher

This doc is hidden because your selected API level for the documentation is . You can change the documentation API level with the selector above the left navigation.

For more information about specifying the API level your app requires, read Supporting Different Platform Versions.