@Test public void concatArrays() { String[] result = Utils.concatArrays(new String[]{"1", "2", "3"}, new String[]{"4", "5"}); assertTrue(Arrays.equals(result, new String[]{"1", "2", "3", "4", "5"})); }
static <T> T[] concatArrays(T[] one, T[] two) { if (one == null) { return two; } else if (two == null) { return one; } final int length = one.length + two.length; final T[] result = (T[]) Array.newInstance(one.getClass().getComponentType(), length); for (int i = 0; i < length; i++) { if (i < one.length) { result[i] = one[i]; } else { result[i] = two[i - one.length]; } } return result; }
Utils { static <T> T[] concatArrays(T[] one, T[] two) { if (one == null) { return two; } else if (two == null) { return one; } final int length = one.length + two.length; final T[] result = (T[]) Array.newInstance(one.getClass().getComponentType(), length); for (int i = 0; i < length; i++) { if (i < one.length) { result[i] = one[i]; } else { result[i] = two[i - one.length]; } } return result; } }
Utils { static <T> T[] concatArrays(T[] one, T[] two) { if (one == null) { return two; } else if (two == null) { return one; } final int length = one.length + two.length; final T[] result = (T[]) Array.newInstance(one.getClass().getComponentType(), length); for (int i = 0; i < length; i++) { if (i < one.length) { result[i] = one[i]; } else { result[i] = two[i - one.length]; } } return result; }  }
Utils { static <T> T[] concatArrays(T[] one, T[] two) { if (one == null) { return two; } else if (two == null) { return one; } final int length = one.length + two.length; final T[] result = (T[]) Array.newInstance(one.getClass().getComponentType(), length); for (int i = 0; i < length; i++) { if (i < one.length) { result[i] = one[i]; } else { result[i] = two[i - one.length]; } } return result; }   }
Utils { static <T> T[] concatArrays(T[] one, T[] two) { if (one == null) { return two; } else if (two == null) { return one; } final int length = one.length + two.length; final T[] result = (T[]) Array.newInstance(one.getClass().getComponentType(), length); for (int i = 0; i < length; i++) { if (i < one.length) { result[i] = one[i]; } else { result[i] = two[i - one.length]; } } return result; }    }