Java Array arrayFlatten(final int[][] arr)

Here you can find the source of arrayFlatten(final int[][] arr)

Description

Flatten a 2D array into a 1D array.

License

Apache License

Parameter

Parameter Description
arr input 2D array

Return

the flattened 1D array ()

Declaration

public static int[] arrayFlatten(final int[][] arr) 

Method Source Code

//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;
    }
}

Related

  1. array_intAddLimit(int[] in, int value, int limit)
  2. arrayed(int arrays, String inner)
  3. arrayEndsWith(final byte[] array, final byte[] str)
  4. arrayExclude(double[] src, int excludeIndex)
  5. arrayFirstIndexOf(final T[] array, final T value)
  6. arrayGetCenter(byte[] array, int location, int length)
  7. arrayIsHave(String[] strs, String str)
  8. arrayLookup(int[] ar, int keystart, int keyend, int forbidden)
  9. arrayMember(String[] array, String member)