public class ReverseListIterator extends Object implements ResettableListIterator
The first call to next() will return the last element
from the list, and so on. The hasNext() method works
in concert with the next() method as expected.
However, the nextIndex() method returns the correct
index in the list, thus it starts high and reduces as the iteration
continues. The previous methods work similarly.
| Constructor and Description |
|---|
ReverseListIterator(List list)
Constructor that wraps a list.
|
| Modifier and Type | Method and Description |
|---|---|
void |
add(Object obj)
Adds a new element to the list between the next and previous elements.
|
boolean |
hasNext()
Checks whether there is another element.
|
boolean |
hasPrevious()
Checks whether there is a previous element.
|
Object |
next()
Gets the next element.
|
int |
nextIndex()
Gets the index of the next element.
|
Object |
previous()
Gets the previous element.
|
int |
previousIndex()
Gets the index of the previous element.
|
void |
remove()
Removes the last returned element.
|
void |
reset()
Resets the iterator back to the start (which is the
end of the list as this is a reversed iterator)
|
void |
set(Object obj)
Replaces the last returned element.
|
public ReverseListIterator(List list)
list - the list to create a reversed iterator forNullPointerException - if the list is nullpublic boolean hasNext()
hasNext in interface IteratorhasNext in interface ListIteratorpublic Object next()
next in interface Iteratornext in interface ListIteratorpublic int nextIndex()
nextIndex in interface ListIteratorpublic boolean hasPrevious()
hasPrevious in interface ListIteratorpublic Object previous()
previous in interface ListIteratorpublic int previousIndex()
previousIndex in interface ListIteratorpublic void remove()
remove in interface Iteratorremove in interface ListIteratorUnsupportedOperationException - if the list is unmodifiableIllegalStateException - if there is no element to removepublic void set(Object obj)
set in interface ListIteratorobj - the object to setUnsupportedOperationException - if the list is unmodifiableIllegalStateException - if the iterator is not in a valid state for setpublic void add(Object obj)
add in interface ListIteratorobj - the object to addUnsupportedOperationException - if the list is unmodifiableIllegalStateException - if the iterator is not in a valid state for setpublic void reset()
reset in interface ResettableIteratorreset in interface ResettableListIteratorCopyright © 2001–2015 The Apache Software Foundation. All rights reserved.