Java Array Reverse reverseArray(T[] arr)

Here you can find the source of reverseArray(T[] arr)

Description

Utility function to reverse an array of any type.

License

BSD License

Parameter

Parameter Description
T Will be automatically determined from the type of object array given
arr The object array to reverse

Return

The reversed object array

Declaration

@SuppressWarnings("unchecked")
public static <T> T[] reverseArray(T[] arr) 

Method Source Code

//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();
    }
}

Related

  1. reverse(T[] array)
  2. reverse(T[] array)
  3. reverse(T[] originalArray)
  4. reverseArray(final T[] arr)
  5. reverseArray(Object[] arr)
  6. reverseArrayList(ArrayList listIn)
  7. reverseList (ArrayList l)
  8. reverseRange(final T[] arr, final int from, final int to)
  9. reverseSortedSet(int[] ints)

  10. HOME | Copyright © www.java2s.com 2016