Class ReverseListIterator

  • All Implemented Interfaces:
    Iterator, ListIterator, ResettableIterator, ResettableListIterator

    @Deprecated(since="2021-04-30")
    public class ReverseListIterator
    extends Object
    implements ResettableListIterator
    Deprecated.
    Commons Collections 3 is in maintenance mode. Commons Collections 4 should be used instead.
    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:
    Commons Collections 3.2
    • Constructor Detail

      • ReverseListIterator

        public ReverseListIterator​(List list)
        Deprecated.
        Constructor that wraps a list.
        Parameters:
        list - the list to create a reversed iterator for
        Throws:
        NullPointerException - if the list is null
    • Method Detail

      • hasNext

        public boolean hasNext()
        Deprecated.
        Checks whether there is another element.
        Specified by:
        hasNext in interface Iterator
        Specified by:
        hasNext in interface ListIterator
        Returns:
        true if there is another element
      • next

        public Object next()
        Deprecated.
        Gets the next element. The next element is the previous in the list.
        Specified by:
        next in interface Iterator
        Specified by:
        next in interface ListIterator
        Returns:
        the next element in the iterator
      • nextIndex

        public int nextIndex()
        Deprecated.
        Gets the index of the next element.
        Specified by:
        nextIndex in interface ListIterator
        Returns:
        the index of the next element in the iterator
      • hasPrevious

        public boolean hasPrevious()
        Deprecated.
        Checks whether there is a previous element.
        Specified by:
        hasPrevious in interface ListIterator
        Returns:
        true if there is a previous element
      • previous

        public Object previous()
        Deprecated.
        Gets the previous element. The next element is the previous in the list.
        Specified by:
        previous in interface ListIterator
        Returns:
        the previous element in the iterator
      • previousIndex

        public int previousIndex()
        Deprecated.
        Gets the index of the previous element.
        Specified by:
        previousIndex in interface ListIterator
        Returns:
        the index of the previous element in the iterator
      • reset

        public void reset()
        Deprecated.
        Resets the iterator back to the start (which is the end of the list as this is a reversed iterator)
        Specified by:
        reset in interface ResettableIterator
        Specified by:
        reset in interface ResettableListIterator