ArgUtils { public static Object[] flatten(Object[] array) { final List<Object> list = new ArrayList<Object>(); if (array != null) { for (Object o : array) { if (o instanceof Object[]) { for (Object oR : flatten((Object[]) o)) { list.add(oR); } } else { list.add(o); } } } return list.toArray(); } private  ArgUtils(); static Object[] flatten(Object[] array);  }
@Test public void testFlatten() { final List<Object> orig = new ArrayList<Object>(); final Object[] struct = new Object[] { new Object[] { new Object[] { create(orig), create(orig), }, create(orig), new Object[] { create(orig), } }, create(orig), new Object[] { create(orig), new Object[] { create(orig), create(orig), } }, create(orig), }; Object[] flat = ArgUtils.flatten(struct); Assert.assertEquals(flat.length, orig.size()); for (int i = 0, max = orig.size(); i < max; i++) { Assert.assertEquals(orig.get(i), flat[i]); } }