Here you can find the source of subarray(boolean[] array, int fromIndex, int length)
Parameter | Description |
---|---|
array | a parameter |
fromIndex | first element in returned array |
length | amount to read from array |
public static boolean[] subarray(boolean[] array, int fromIndex, int length)
//package com.java2s; /**/* ww w. j av a 2 s. co m*/ * A simple class comprised of various tools used in handling of boolean arrays and values. * * @author Raymond Berg www.rwberg.org * * Use is made available under the Creative Commons License. * Feel free to use but leave attribution to original author throughout use. */ public class Main { /** * Building on the arraycopy function in System, this function returns a * "subarray" of a larger array. The length parameter determines the * length of the resulting array. Standard out of bounds exceptions on length * can be expected. * * @see {@link booleanUtil#subarray(boolean[], int)} * @param array * @param fromIndex * first element in returned array * @param length * amount to read from array * @return boolean array consisting of elements in range * [fromIndex,fromIndex+length] */ public static boolean[] subarray(boolean[] array, int fromIndex, int length) { boolean[] tempArray = new boolean[length]; try { System.arraycopy(array, fromIndex, tempArray, 0, tempArray.length); } catch (ArrayIndexOutOfBoundsException e) { System.out.println("@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@"); System.out.println("Array of length:" + array.length); System.out.println("From index with length:" + fromIndex + "," + length); System.out.println("@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@"); } return tempArray; } /** * Building on the arraycopy function in System, this function returns a * "subarray" of a larger array. Function returns subarray starting at * fromIndex and ending with the final element of the array. * * @see booleanUtil#subarray(boolean[], int, int) * @param array * @param fromIndex * @return */ public static boolean[] subarray(boolean[] array, int fromIndex) { boolean[] tempArray = new boolean[array.length - fromIndex]; System.arraycopy(array, fromIndex, tempArray, 0, tempArray.length); return tempArray; } }