Here you can find the source of reverseArray(final T[] arr)
Parameter | Description |
---|---|
T | The content type. |
arr | The array to reverse. |
public static <T> Iterable<T> reverseArray(final T[] arr)
//package com.java2s; //License from project: Open Source License import java.util.Iterator; public class Main { /**//from w w w. j av a2 s .c om * Reverses the given array for iteration. The actual array is not modified. * * @param <T> The content type. * @param arr The array to reverse. * @return The reversed array. */ public static <T> Iterable<T> reverseArray(final T[] arr) { return new Iterable<T>() { @Override public Iterator<T> iterator() { return new Iterator<T>() { private int pos = arr.length; @Override public boolean hasNext() { return pos > 0; } @Override public T next() { return arr[--pos]; } @Override // TODO #43 -- Java 8 simplification public void remove() { throw new UnsupportedOperationException(); } }; } }; } }