Package java.util
Interface ListIterator<E>
-
-
Method Summary
All Methods Instance Methods Abstract Methods Modifier and Type Method Description voidadd(E object)Inserts the specified object into the list betweennextandprevious.booleanhasNext()Returns whether there are more elements to iterate.booleanhasPrevious()Returns whether there are previous elements to iterate.Enext()Returns the next object in the iteration.intnextIndex()Returns the index of the next object in the iteration.Eprevious()Returns the previous object in the iteration.intpreviousIndex()Returns the index of the previous object in the iteration.voidremove()Removes the last object returned bynextorpreviousfrom the list.voidset(E object)Replaces the last object returned bynextorpreviouswith the specified object.
-
-
-
Method Detail
-
add
void add(E object)
Inserts the specified object into the list betweennextandprevious. The object inserted will be the previous object.- Parameters:
object- the object to insert.- Throws:
java.lang.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
boolean hasNext()
Returns whether there are more elements to iterate.
-
hasPrevious
boolean hasPrevious()
Returns whether there are previous elements to iterate.- Returns:
trueif there are previous elements,falseotherwise.- See Also:
previous()
-
next
E next()
Returns the next object in the iteration.
-
nextIndex
int nextIndex()
Returns the index of the next object in the iteration.- Returns:
- the index of the next object, or the size of the list if the iterator is at the end.
- Throws:
java.util.NoSuchElementException- if there are no more elements.- See Also:
next()
-
previous
E previous()
Returns the previous object in the iteration.- Returns:
- the previous object.
- Throws:
java.util.NoSuchElementException- if there are no previous elements.- See Also:
hasPrevious()
-
previousIndex
int previousIndex()
Returns the index of the previous object in the iteration.- Returns:
- the index of the previous object, or -1 if the iterator is at the beginning.
- Throws:
java.util.NoSuchElementException- if there are no previous elements.- See Also:
previous()
-
remove
void remove()
Removes the last object returned bynextorpreviousfrom the list.- Specified by:
removein interfaceIterator<E>- Throws:
java.lang.UnsupportedOperationException- if removing is not supported by the list being iterated.java.lang.IllegalStateException- ifnextorprevioushave not been called, orremoveoraddhave already been called after the last call tonextorprevious.
-
set
void set(E object)
Replaces the last object returned bynextorpreviouswith the specified object.- Parameters:
object- the object to set.- Throws:
java.lang.UnsupportedOperationException- if setting is not supported by the list being iteratedClassCastException- if the class of the object is inappropriate for the list.IllegalArgumentException- if the object cannot be added to the list.java.lang.IllegalStateException- ifnextorprevioushave not been called, orremoveoraddhave already been called after the last call tonextorprevious.
-
-