code: public static Object flatten(Object array) {
          Preconditions.checkArgument(array.getClass().isArray(), "array");
  
          Class<?> type = getType(array);
          int[] dimensions = getDimensions(array);
          int length = length(dimensions);
  
          Object flattened = Array.newInstance(type, length);
  
          flatten(array, flattened, dimensions, 0);
  
          return flattened;
      }
docs: Flatten a multi-dimensional array into a one-dimensional array.
  
  @param array the array to flatten.
  @return a 1-dimensional array.