To split an array in Java, use the
Arrays.copyOfRange
method.Here's how you do it:
int[] array = new int[] { 14, 3, 22, 5, 7, 118, 11, 55 };
int[] firstHalf = Arrays.copyOfRange(array, 0, array.length / 2);
int[] secondHalf = Arrays.copyOfRange(array, array.length / 2, array.length);
System.out.println(Arrays.toString(firstHalf)); // [14, 3, 22, 5]
System.out.println(Arrays.toString(secondHalf)); // [7, 118, 11, 55]