Here you can find the source of subArray(Object[] data, int startIndex, int endIndex)
Parameter | Description |
---|---|
data | The array to get the sub array from |
startIndex | The first index of the subarray |
endIndex | The first index not in the subarray (last index +1) |
public static Object[] subArray(Object[] data, int startIndex, int endIndex)
//package com.java2s; //License from project: Open Source License public class Main { /**// w w w .j a va 2 s . c o m * Get a part on an array * @param data The array to get the sub array from * @param startIndex The first index of the subarray * @param endIndex The first index not in the subarray (last index +1) * @return an array with the elements from data in the fields startIndex to endIndex-1 */ public static Object[] subArray(Object[] data, int startIndex, int endIndex) { Object[] output = new Object[endIndex - startIndex]; for (int i = startIndex; i < endIndex; i++) { output[i - startIndex] = data[i]; } return output; } /** * Get a part on an array * @param data The array to get the sub array from * @param startIndex The first index of the subarray * @param endIndex The first index not in the subarray (last index +1) * @return an array with the elements from data in the fields startIndex to endIndex-1 */ public static boolean[] subArray(boolean[] data, int startIndex, int endIndex) { boolean[] output = new boolean[endIndex - startIndex]; for (int i = startIndex; i < endIndex; i++) { output[i - startIndex] = data[i]; } return output; } /** * Get a part on an array * @param data The array to get the sub array from * @param startIndex The first index of the subarray * @param endIndex The first index not in the subarray (last index +1) * @return an array with the elements from data in the fields startIndex to endIndex-1 */ public static double[] subArray(double[] data, int startIndex, int endIndex) { double[] output = new double[endIndex - startIndex]; for (int i = startIndex; i < endIndex; i++) { output[i - startIndex] = data[i]; } return output; } }