Java Array Flatten flatten(E[][] a)

Here you can find the source of flatten(E[][] a)

Description

flatten

License

Open Source License

Parameter

Parameter Description
a a parameter
E a parameter

Return

a flattened array list of all elements in a

Declaration

public static <E> ArrayList<E> flatten(E[][] a) 

Method Source Code

//package com.java2s;
/*******************************************************************************
 * OscaR is free software: you can redistribute it and/or modify
 * it under the terms of the GNU Lesser General Public License as published by
 * the Free Software Foundation, either version 2.1 of the License, or
 * (at your option) any later version./*from   ww w. j av a  2 s.  c om*/
 *   
 * OscaR is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU Lesser General Public License  for more details.
 *   
 * You should have received a copy of the GNU Lesser General Public License along with OscaR.
 * If not, see http://www.gnu.org/licenses/lgpl-3.0.en.html
 ******************************************************************************/

import java.util.ArrayList;

public class Main {
    /**
     *
     * @param a
     * @param <E>
     * @return a flattened array list of all elements in a
     */
    public static <E> ArrayList<E> flatten(E[][] a) {
        ArrayList<E> res = new ArrayList<E>();
        for (int i = 0; i < a.length; i++) {
            for (int j = 0; j < a[i].length; j++) {
                res.add(a[i][j]);
            }
        }
        return res;

    }
}

Related

  1. flatten(byte[][] first)
  2. flatten(final Object[] array)
  3. flatten(float[][] mat)
  4. flatten(Object[] array)
  5. flatten(Object[] array)