Here you can find the source of reverseArray(T[] arr)
Parameter | Description |
---|---|
T | Will be automatically determined from the type of object array given |
arr | The object array to reverse |
@SuppressWarnings("unchecked") public static <T> T[] reverseArray(T[] arr)
//package com.java2s; /**//from w ww .ja v a 2 s . c om * CamanJ - Java Image Manipulation * Ported from the CamanJS Javascript library * * Copyright 2011, Ryan LeFevre * Licensed under the new BSD License * See LICENSE for more info. * * Project Home: http://github.com/meltingice/CamanJ */ import java.util.Arrays; import java.util.Collections; import java.util.List; public class Main { /** * Utility function to reverse an array of any type. * * @param <T> * Will be automatically determined from the type of object array * given * @param arr * The object array to reverse * @return The reversed object array */ @SuppressWarnings("unchecked") public static <T> T[] reverseArray(T[] arr) { List<T> list = Arrays.asList(arr); Collections.reverse(list); return (T[]) list.toArray(); } }