Java Array Two Dimension to One Dimension array2Dto1D(int[][] d2)

Here you can find the source of array2Dto1D(int[][] d2)

Description

array Dto D

License

Open Source License

Declaration

public static int[] array2Dto1D(int[][] d2) 

Method Source Code

//package com.java2s;
/* ArrayUtil.java 1.0 2010-2-2
 * //  www  . j a va  2  s. c o m
 * Copyright (c) 2010 by Chen Zhiwu
 * All rights reserved.
 * 
 * The copyright of this software is own by the authors.
 * You may not use, copy or modify this software, except
 * in accordance with the license agreement you entered into 
 * with the copyright holders. For details see accompanying license
 * terms.
 */

public class Main {
    public static int[] array2Dto1D(int[][] d2) {
        int hight = d2.length;
        int width = d2[0].length;
        int[] modImgArray = new int[width * hight];
        for (int i = 0; i < hight; i++) {
            System.arraycopy(d2[i], 0, modImgArray, i * width, width);
        }
        return modImgArray;
    }

    public static void array2Dto1D(int[][] d2, int[] d1) {
        int hight = d2.length;
        int width = d2[0].length;
        for (int i = 0; i < hight; i++) {
            System.arraycopy(d2[i], 0, d1, i * width, width);
        }
    }
}

Related

  1. array2dCopy(Object[][] src, Object[][] dest)
  2. array2DTo1D(double[][] In)
  3. array2dTo1d(float[][] in)
  4. array2Dto1D(int m, int n, double[][] a)
  5. array2DTo1D(int[][] array2D)
  6. array2Square(short[] ar, int rows, int cols)