@SuppressWarnings("unchecked")
  public static <T> T[] concat(Class<T> type, T[]... arrays) {
    T[] result = (T[]) Array.newInstance(type, totalLength(arrays));

    int currentLength = 0;

    for (T[] array : arrays) {
      int length = array.length;
      if (length > 0) {
        System.arraycopy(array, 0, result, currentLength, length);
        currentLength += length;
      }
    }

    return result;
  }
@Test
  public void testConcatWithDifferentLengthArrays() {
    Integer[] array1 = {1, 2, 3};
    Integer[] array2 = {4, 5};
    Integer[] array3 = {6, 7, 8, 9};

    Integer[] result = ArrayUtil.concat(Integer.class, array1, array2, array3);
    assertThat(result).isEqualTo(new Integer[] {1, 2, 3, 4, 5, 6, 7, 8, 9});
  }