@Test public void testArraysMerge() { String[] a1 = { "b", "y", "z" }; String[] a2 = {}; String[] a3 = { "b", "d", "e", "f" }; String[] result = ArrayUtils.arrayMerge(a1, a2, a3); String[] expected = { "b", "y", "z", "b", "d", "e", "f" }; assertTrue(Arrays.equals(expected, result)); }
@SuppressWarnings("unchecked") public static <T> T[] arrayMerge(T[]... arrays) { int count = 0; Class<?> klass = null; for (T[] array : arrays) { count += array.length; if (klass == null && array.length > 0) { klass = array[0].getClass(); } } if (count == 0) { return arrays[0]; } T[] rv = (T[]) Array.newInstance(klass, count); int start = 0; for (T[] array : arrays) { System.arraycopy(array, 0, rv, start, array.length); start += array.length; } return rv; }
ArrayUtils { @SuppressWarnings("unchecked") public static <T> T[] arrayMerge(T[]... arrays) { int count = 0; Class<?> klass = null; for (T[] array : arrays) { count += array.length; if (klass == null && array.length > 0) { klass = array[0].getClass(); } } if (count == 0) { return arrays[0]; } T[] rv = (T[]) Array.newInstance(klass, count); int start = 0; for (T[] array : arrays) { System.arraycopy(array, 0, rv, start, array.length); start += array.length; } return rv; } }
ArrayUtils { @SuppressWarnings("unchecked") public static <T> T[] arrayMerge(T[]... arrays) { int count = 0; Class<?> klass = null; for (T[] array : arrays) { count += array.length; if (klass == null && array.length > 0) { klass = array[0].getClass(); } } if (count == 0) { return arrays[0]; } T[] rv = (T[]) Array.newInstance(klass, count); int start = 0; for (T[] array : arrays) { System.arraycopy(array, 0, rv, start, array.length); start += array.length; } return rv; } private  ArrayUtils(); }
ArrayUtils { @SuppressWarnings("unchecked") public static <T> T[] arrayMerge(T[]... arrays) { int count = 0; Class<?> klass = null; for (T[] array : arrays) { count += array.length; if (klass == null && array.length > 0) { klass = array[0].getClass(); } } if (count == 0) { return arrays[0]; } T[] rv = (T[]) Array.newInstance(klass, count); int start = 0; for (T[] array : arrays) { System.arraycopy(array, 0, rv, start, array.length); start += array.length; } return rv; } private  ArrayUtils(); @SuppressWarnings("unchecked") static T[] arrayMerge(T[]... arrays); @SuppressWarnings("unchecked") static T[] intersect(final T[]... arrays); }
ArrayUtils { @SuppressWarnings("unchecked") public static <T> T[] arrayMerge(T[]... arrays) { int count = 0; Class<?> klass = null; for (T[] array : arrays) { count += array.length; if (klass == null && array.length > 0) { klass = array[0].getClass(); } } if (count == 0) { return arrays[0]; } T[] rv = (T[]) Array.newInstance(klass, count); int start = 0; for (T[] array : arrays) { System.arraycopy(array, 0, rv, start, array.length); start += array.length; } return rv; } private  ArrayUtils(); @SuppressWarnings("unchecked") static T[] arrayMerge(T[]... arrays); @SuppressWarnings("unchecked") static T[] intersect(final T[]... arrays);  }