Java Array Invert invert(T[] array)

Here you can find the source of invert(T[] array)

Description

Inverts the array.

License

Open Source License

Parameter

Parameter Description
array The array to be inverted
T The type of the array

Return

the inverted array which is the same object as the parameter array

Declaration

public static <T> T[] invert(T[] array) 

Method Source Code

//package com.java2s;
//License from project: Open Source License 

public class Main {
    /**// w ww. j  a  v  a 2s. c o m
     * Inverts the <code>array</code>.
     *
     * @param array The array to be inverted
     * @param <T> The type of the array
     *
     * @return the inverted array which is the same object as the parameter array
     */
    public static <T> T[] invert(T[] array) {
        if (array == null)
            return null;

        int j = array.length - 1;
        for (int i = 0; i < array.length / 2; i++) {
            T element = array[i];
            array[i] = array[j];
            array[j--] = element;
        }
        return array;
    }
}

Related

  1. invert(int[] bits)
  2. invert(int[] v)
  3. invert(int[][] clustered)
  4. invert(Object[] array)
  5. invert(Object[] objArray)
  6. invert3x3(float m[], float inv[])
  7. invert4x4(float m[], float inv[])
  8. invertArray(final byte[] array)
  9. invertArray(int[] a, int top)