Here you can find the source of invertArray(Object[] data)
Object array
backwards
Parameter | Description |
---|---|
data | The array to be inverted |
public static Object[] invertArray(Object[] data)
//package com.java2s; /* Copyright 2014 BossLetsPlays(Matthew Rogers) * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License.//from w w w .j a va 2s. c o m */ public class Main { /** * Turns an <code>Object array</code> backwards * @param data The array to be inverted * @return The inverted array */ public static Object[] invertArray(Object[] data) { Object[] result = new Object[data.length]; int n = 0; for (int i = data.length - 1; i >= 0; i--) { result[n] = data[i]; n++; } return result; } /** * Turns an <code>int array</code> backwards * @param data The array to be inverted * @return The inverted array */ public static int[] invertArray(int[] data) { int[] result = new int[data.length]; int n = 0; for (int i = data.length - 1; i >= 0; i--) { result[n] = data[i]; n++; } return result; } /** * Turns a <code>double array</code> backwards * @param data The array to be inverted * @return The inverted array */ public static double[] invertArray(double[] data) { double[] result = new double[data.length]; int n = 0; for (int i = data.length - 1; i >= 0; i--) { result[n] = data[i]; n++; } return result; } /** * Turns a <code>float array</code> backwards * @param data The array to be inverted * @return The inverted array */ public static float[] invertArray(float[] data) { float[] result = new float[data.length]; int n = 0; for (int i = data.length - 1; i >= 0; i--) { result[n] = data[i]; n++; } return result; } /** * Turns a <code>boolean array</code> backwards * @param data The array to be inverted * @return The inverted array */ public static boolean[] invertArray(boolean[] data) { boolean[] result = new boolean[data.length]; int n = 0; for (int i = data.length - 1; i >= 0; i--) { result[n] = data[i]; n++; } return result; } }