Java Array Flatten flatten(Object[] array)

Here you can find the source of flatten(Object[] array)

Description

flatten

License

Apache License

Declaration

public static Object[] flatten(Object[] array) 

Method Source Code

//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]);
        }
    }
}

Related

  1. flatten(byte[][] first)
  2. flatten(E[][] a)
  3. flatten(final Object[] array)
  4. flatten(float[][] mat)
  5. flatten(Object[] array)
  6. flatten(Object[] lines, String sep)
  7. flatten(String s[])
  8. flatten(String[] strings, String separator)
  9. flattenArguments(String[] arguments)