Here you can find the source of reverseList(final List
Parameter | Description |
---|---|
T | The content type. |
list | The list to reverse. |
public static <T> Iterable<T> reverseList(final List<T> list)
//package com.java2s; //License from project: Open Source License import java.util.Iterator; import java.util.List; import java.util.ListIterator; public class Main { /**// w w w . ja va2 s . c om * Reverses the given list for iteration. The actual list is not modified. * * @param <T> The content type. * @param list The list to reverse. * @return The reversed list. */ public static <T> Iterable<T> reverseList(final List<T> list) { return new Iterable<T>() { @Override public Iterator<T> iterator() { final ListIterator<T> li = list.listIterator(list.size()); return new Iterator<T>() { @Override public boolean hasNext() { return li.hasPrevious(); } @Override public T next() { return li.previous(); } @Override public void remove() { li.remove(); } }; } }; } }