ArrayUtil { 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; }  static Object flatten(Object array); static Object unflatten(Object array, int[] dimensions); static int[] getDimensions(Object array); static Class<?> getType(Object array); static Object transformArray(Object array, Function<F, T> transform, Class<T> toType);  }
@Test(dataProvider = "arrays") public void testFlatten(Object array) throws Exception { Object flattened = ArrayUtil.flatten(array); for (int i = 0; i < Array.getLength(flattened); i++) { assertEquals(Array.get(flattened, i), i); } }