Here you can find the source of arrayCopy(T[] x)
public static <T> T[] arrayCopy(T[] x)
//package com.java2s; //License from project: Open Source License import java.util.Arrays; public class Main { public static <T> T[] arrayCopy(T[] x) { return arrayCopy(x, true); }/*from w w w . ja v a 2 s . c o m*/ public static <T> T[] arrayCopy(T[] x, boolean notNull) { int z = 0; T[] l = x.clone(); for (int i = 0; i < x.length; i++) { T y = x[i]; l[i] = null; if (!notNull || y != null) { l[z] = y; z++; } } T[] n = Arrays.copyOf(l, z); return n; } public static int[] arrayCopy(int[] x) { return arrayCopy(x, false); } public static int[] arrayCopy(int[] x, boolean notZero) { int z = 0; int[] l = new int[x.length + 1]; for (int i = 0; i < x.length; i++) { int y = x[i]; if (!notZero || y != 0) { l[z] = y; z++; } } int[] n = new int[z]; System.arraycopy(l, 0, n, 0, z); return n; } public static byte[] arrayCopy(byte[] x) { return arrayCopy(x, false); } public static byte[] arrayCopy(byte[] x, boolean notZero) { int z = 0; byte[] l = new byte[x.length + 1]; for (int i = 0; i < x.length; i++) { byte y = x[i]; if (!notZero || y != 0) { l[z] = y; z++; } } byte[] n = new byte[z]; System.arraycopy(l, 0, n, 0, z); return n; } public static char[] arrayCopy(char[] x) { return arrayCopy(x, false); } public static char[] arrayCopy(char[] x, boolean notZero) { int z = 0; char[] l = new char[x.length + 1]; for (int i = 0; i < x.length; i++) { char y = x[i]; if (!notZero || y != 0) { l[z] = y; z++; } } char[] n = new char[z]; System.arraycopy(l, 0, n, 0, z); return n; } public static <T> T[] arrayCopy(T[] x, int size) { int z = 0; T[] l = x.clone(); for (int i = 0; i < x.length; i++) { T y = x[i]; l[i] = null; if (y != null) { l[z] = y; z++; } } T[] n = Arrays.copyOf(l, size); return n; } }