This utility function returns an array copy containing of passed row index of a given 2D array - Java Collection Framework

Java examples for Collection Framework:Array Contain

Description

This utility function returns an array copy containing of passed row index of a given 2D array

Demo Code


//package com.java2s;

public class Main {
    /**// w  w  w.ja  va 2  s  .  c  o  m
     * This utility function returns an array copy containing of passed row
     * index of a given 2D array
     * 
     * @param twoDdoubleArray
     *            the original 2D double array from which a row will be copied
     *            and return as an array
     * @param row
     *            a row index indicating the row which needs to be taken out
     *            (copied and returned)
     * @return an array (double) containing a copy of its needed row (index
     *         passed as argument)
     */
    public static double[] rowCopy(double[][] twoDdoubleArray, int row) {
        double[] rowCopyArr = new double[twoDdoubleArray[0].length];
        for (int col = 0; col < twoDdoubleArray[0].length; col++) {
            rowCopyArr[col] = twoDdoubleArray[row][col];
        }
        return rowCopyArr;
    }
}

Related Tutorials