Here you can find the source of split(final int[] array)
Parameter | Description |
---|---|
array | array to split |
static int[][] split(final int[] array)
//package com.java2s; //License from project: Open Source License import java.util.Arrays; public class Main { /**/*from ww w . java 2 s . c o m*/ * Splits array into two smaller arrays. If the array length is odd then the right part (0 index) will always be bigger. * Example: array 2, 1, 3, 5, 4 will be splitted into 2, 1 and 3, 5, 4, * * @param array array to split * @return two arrays as a split result, 0 index - left part (equal by length or bigger then right part), 1 index - right part. */ static int[][] split(final int[] array) { final int[] part1 = Arrays.copyOfRange(array, 0, array.length / 2); final int[] part2 = Arrays.copyOfRange(array, array.length / 2, array.length); return twoDimensionalArray(part1, part2); } /** * Creates one two-dimensional array from two one-dimensional arrays. * * @param array1 first part of two dimensional array (at index 0) * @param array2 second part of two dimensional array (at index 1) * @return two dimensional array from array1 and array2 */ static int[][] twoDimensionalArray(final int[] array1, final int[] array2) { final int[][] result = new int[2][]; result[0] = array1; result[1] = array2; return result; } }