public static < T > Iterator < T > reverseIterator ( final List < T > list ) { return new Iterator < T > ( ) { private int next = list . size ( ) - 1 ; @ Override @ Pure public boolean hasNext ( ) { return this . next >= 0 ; } @ Override public T next ( ) { final int n = this . next ; -- this . next ; try { return list . get ( n ) ; } catch ( IndexOutOfBoundsException exception ) { throw new NoSuchElementException ( ) ; } } } ; }
Replies an iterator that goes from end to start of the given list .