Here you can find the source of arrayFlatten(final int[][] arr)
Parameter | Description |
---|---|
arr | input 2D array |
public static int[] arrayFlatten(final int[][] arr)
//package com.java2s; //License from project: Apache License public class Main { /**/* w w w .j a v a 2s . c om*/ * Flatten a 2D array into a 1D array. * * @param arr input 2D array * @return the flattened 1D array () */ public static int[] arrayFlatten(final int[][] arr) { int size = 0; for (int[] e : arr) { size += e.length; } int[] result = new int[size]; int i = 0; for (int[] e : arr) { for (int v : e) { result[i] = v; i++; } } return result; } }