Java Array Flatten flattenArray(Object... objects)

Here you can find the source of flattenArray(Object... objects)

Description

flatten Array

License

Open Source License

Declaration

public static Object[] flattenArray(Object... objects) 

Method Source Code

//package com.java2s;
/*******************************************************************************
 * Copyright (c) 2014 Gabriel Skantze./*from www.jav a2 s .c om*/
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the GNU Public License v3.0
 * which accompanies this distribution, and is available at
 * http://www.gnu.org/licenses/gpl.html
 * 
 * Contributors:
 *     Gabriel Skantze - initial API and implementation
 ******************************************************************************/

import java.util.ArrayList;
import java.util.Arrays;

import java.util.List;

public class Main {
    public static Object[] flattenArray(Object... objects) {
        List result = new ArrayList();
        for (Object obj : objects) {
            if (obj instanceof Object[]) {
                result.addAll(Arrays.asList((Object[]) obj));
            } else if (obj instanceof List) {
                result.addAll((List) obj);
            } else {
                result.add(obj);
            }
        }
        return result.toArray();
    }
}

Related

  1. flatten(Object[] array)
  2. flatten(Object[] lines, String sep)
  3. flatten(String s[])
  4. flatten(String[] strings, String separator)
  5. flattenArguments(String[] arguments)
  6. flattenArray(Object[] words)
  7. flattenArray(String[] aString)
  8. flattenBytes(byte[] b)
  9. flattenIndices(int[] indices, int[] extents)