Here you can find the source of invert(T[] array)
array
.
Parameter | Description |
---|---|
array | The array to be inverted |
T | The type of the array |
public static <T> T[] invert(T[] array)
//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; } }