Here you can find the source of iterateReverse(final List
public static <T> Iterable<T> iterateReverse(final List<T> elements)
//package com.java2s; //License from project: Apache License import java.util.Collection; import java.util.Iterator; import java.util.List; import java.util.ListIterator; public class Main { public static <T> Iterable<T> iterateReverse(final List<T> elements) { return new Iterable<T>() { @Override//from w ww .j av a 2 s . com public Iterator<T> iterator() { return new Iterator<T>() { ListIterator<T> it = elements.listIterator(elements.size()); @Override public boolean hasNext() { return it.hasPrevious(); } @Override public T next() { return it.previous(); } @Override public void remove() { it.remove(); } }; } }; } @SuppressWarnings("rawtypes") public static int size(Iterable<?> i) { if (i instanceof Collection) { return ((Collection) i).size(); } int size = 0; for (@SuppressWarnings("unused") Object o : i) { size++; } return size; } }