Here you can find the source of flatten(double[][] array)
public static double[] flatten(double[][] array)
//package com.java2s; //License from project: Open Source License public class Main { public static double[] flatten(double[][] array) { //check parameter.. for (int i = 1; i < array.length; ++i) { if (array[i].length > array[0].length) { throw new IllegalArgumentException(String.format( "Subarray has too many elements (%d). Must be at most array[0].length (%d).%n", array[i].length, array[0].length)); }/* ww w .ja v a 2 s . c om*/ } //end of check double[] res = new double[array.length * array[0].length]; for (int i = 0; i < res.length; i++) { res[i] = array[i / array[0].length][i % array[0].length]; } return res; } public static boolean[] flatten(boolean[][] array) { //check parameter.. for (int i = 1; i < array.length; ++i) { if (array[i].length > array[0].length) { throw new IllegalArgumentException(String.format( "Subarray has too many elements (%d). Must be at most array[0].length (%d).%n", array[i].length, array[0].length)); } } //end of check boolean[] res = new boolean[array.length * array[0].length]; for (int i = 0; i < res.length; i++) { res[i] = array[i / array[0].length][i % array[0].length]; } return res; } }