Here you can find the source of flatten(Object[] array)
public static Object[] flatten(Object[] array)
//package com.java2s; //License from project: Apache License import java.util.ArrayList; import java.util.List; public class Main { public static Object[] flatten(Object[] array) { ArrayList result = new ArrayList(); for (int i = 0; i < array.length; i++) { if (Object[].class.isAssignableFrom(array[i].getClass())) { appendArrayToList((Object[]) array[i], result); } else { result.add(array[i]);//ww w . j a v a 2s . co m } } return result.toArray(); } /** * Append the array's elements into the existing list. * @param array - Array of elements to be appended into the list * @param list - The target list */ public static void appendArrayToList(Object[] array, List list) { for (int i = 0; i < array.length; i++) { list.add(array[i]); } } }