Here you can find the source of Flatten(int[][] in, int[] out)
public static final int[] Flatten(int[][] in, int[] out)
//package com.java2s; //License from project: Open Source License public class Main { public static final int[] Flatten(int[][] in, int[] out) { if (out == null || out.length < NElem(in)) out = new int[NElem(in)]; int ind = 0; for (int i = 0, s = in.length; i < s; i++) { System.arraycopy(in[i], 0, out, ind, in[i].length); ind += in[i].length;//from w w w . j a v a2s . c om } return out; } public static final int[] Flatten(int[][] in) { return Flatten(in, null); } public static final int[] Flatten(int[][][] in, int[] out) { if (out == null || out.length < NElem(in)) out = new int[NElem(in)]; int ind = 0; for (int i = 0, s = in.length; i < s; i++) { int temp[] = Flatten(in[i]); System.arraycopy(temp, 0, out, ind, temp.length); ind += temp.length; } return out; } public static final int[] Flatten(int[][][] in) { return Flatten(in, null); } public static final int NElem(Object in) { if (in instanceof int[]) return ((int[]) in).length; else { int sum = 0; for (int i = 0, s = ((Object[]) in).length; i < s; i++) sum += NElem(((Object[]) in)[i]); return sum; } } }