Here you can find the source of flatten(int[][] arr)
public static int[] flatten(int[][] arr)
//package com.java2s; //License from project: Apache License public class Main { public static int[] flatten(int[][] arr) { int[] ret = new int[arr.length * arr[0].length]; int count = 0; for (int i = 0; i < arr.length; i++) for (int j = 0; j < arr[i].length; j++) ret[count++] = arr[i][j]; return ret; }/*from ww w . j a va2s . com*/ public static double[] flatten(double[][] arr) { double[] ret = new double[arr.length * arr[0].length]; int count = 0; for (int i = 0; i < arr.length; i++) for (int j = 0; j < arr[i].length; j++) ret[count++] = arr[i][j]; return ret; } }