Here you can find the source of reverse(final List
public static <E> Iterable<E> reverse(final List<E> list)
//package com.java2s; /*//from w w w.j a v a 2 s . c o m * Copyright (c) 2012-2014, Parallel Universe Software Co. All rights reserved. * * This program and the accompanying materials are dual-licensed under * either the terms of the Eclipse Public License v1.0 as published by * the Eclipse Foundation * * or (per the licensee's choosing) * * under the terms of the GNU Lesser General Public License version 3.0 * as published by the Free Software Foundation. */ import java.util.Deque; import java.util.Iterator; import java.util.List; import java.util.ListIterator; public class Main { public static <E> Iterable<E> reverse(final Deque<E> deque) { return new Iterable<E>() { @Override public Iterator<E> iterator() { return deque.descendingIterator(); } }; } public static <E> Iterable<E> reverse(final List<E> list) { return new Iterable<E>() { @Override public Iterator<E> iterator() { final ListIterator<E> it = list.listIterator(list.size()); return new Iterator<E>() { @Override public boolean hasNext() { return it.hasPrevious(); } @Override public E next() { return it.previous(); } @Override public void remove() { it.remove(); } }; } }; } }