Class ReverseListIterator<E>
java.lang.Object
org.apache.commons.collections4.iterators.ReverseListIterator<E>
- Type Parameters:
- E- the type of elements returned by this iterator.
- All Implemented Interfaces:
- Iterator<E>,- ListIterator<E>,- OrderedIterator<E>,- ResettableIterator<E>,- ResettableListIterator<E>
Iterates backwards through a List, starting with the last element
 and continuing to the first. This is useful for looping around
 a list in reverse order without needing to actually reverse the list.
 
 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.
 
- Since:
- 3.2
- 
Constructor SummaryConstructors
- 
Method SummaryModifier and TypeMethodDescriptionvoidAdds a new element to the list between the next and previous elements.booleanhasNext()Checks whether there is another element.booleanChecks whether there is a previous element.next()Gets the next element.intGets the index of the next element.previous()Gets the previous element.intGets the index of the previous element.voidremove()Removes the last returned element.voidreset()Resets the iterator back to the start (which is the end of the list as this is a reversed iterator)voidReplaces the last returned element.Methods inherited from class java.lang.Objectclone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface java.util.IteratorforEachRemaining
- 
Constructor Details- 
ReverseListIteratorConstructor that wraps a list.- Parameters:
- list- the list to create a reversed iterator for
- Throws:
- NullPointerException- if the list is null
 
 
- 
- 
Method Details- 
addAdds a new element to the list between the next and previous elements.- Specified by:
- addin interface- ListIterator<E>
- Parameters:
- obj- the object to add
- Throws:
- UnsupportedOperationException- if the list is unmodifiable
- IllegalStateException- if the iterator is not in a valid state for set
 
- 
hasNext
- 
hasPreviousChecks whether there is a previous element.- Specified by:
- hasPreviousin interface- ListIterator<E>
- Specified by:
- hasPreviousin interface- OrderedIterator<E>
- Returns:
- true if there is a previous element
 
- 
next
- 
nextIndexGets the index of the next element.- Specified by:
- nextIndexin interface- ListIterator<E>
- Returns:
- the index of the next element in the iterator
 
- 
previousGets the previous element. The next element is the previous in the list.- Specified by:
- previousin interface- ListIterator<E>
- Specified by:
- previousin interface- OrderedIterator<E>
- Returns:
- the previous element in the iterator
 
- 
previousIndexGets the index of the previous element.- Specified by:
- previousIndexin interface- ListIterator<E>
- Returns:
- the index of the previous element in the iterator
 
- 
removeRemoves the last returned element.- Specified by:
- removein interface- Iterator<E>
- Specified by:
- removein interface- ListIterator<E>
- Throws:
- UnsupportedOperationException- if the list is unmodifiable
- IllegalStateException- if there is no element to remove
 
- 
resetResets the iterator back to the start (which is the end of the list as this is a reversed iterator)- Specified by:
- resetin interface- ResettableIterator<E>
 
- 
setReplaces the last returned element.- Specified by:
- setin interface- ListIterator<E>
- Parameters:
- obj- the object to set
- Throws:
- UnsupportedOperationException- if the list is unmodifiable
- IllegalStateException- if the iterator is not in a valid state for set
 
 
-