Java Array Copy copyArray(double[] array)

Here you can find the source of copyArray(double[] array)

Description

Creates a copy of the given array.

License

Open Source License

Parameter

Parameter Description
array the array

Return

the copy of the given array

Declaration

public static double[] copyArray(double[] array) 

Method Source Code

//package com.java2s;
//License from project: Open Source License 

public class Main {
    /**//  w ww. j a v a  2  s. c  o  m
     * Creates a copy of the given array.
     * @param array the array
     * @return the copy of the given array
     */
    public static double[] copyArray(double[] array) {
        double[] retVal = new double[array.length];
        System.arraycopy(array, 0, retVal, 0, array.length);
        return retVal;
    }

    /**
     * Creates a copy of the given array.
     * @param array the array
     * @return the copy of the given array
     */
    public static int[] copyArray(int[] array) {
        int[] retVal = new int[array.length];
        System.arraycopy(array, 0, retVal, 0, array.length);
        return retVal;
    }

    /**
     * Creates a copy of the given array.
     * @param array the array
     * @return the copy of the given array
     */
    public static boolean[] copyArray(boolean[] array) {
        boolean[] retVal = new boolean[array.length];
        System.arraycopy(array, 0, retVal, 0, array.length);
        return retVal;
    }

    /**
     * Creates a copy of a sub-array of the given array.
     * @param array the array
     * @param start the start index (inclusive) of the sub-array
     * @param length number of elements in the sub-array
     * @return copy of sub-array of the given array.
     */
    public static double[] copyArray(double[] array, int start, int length) {
        double[] retVal = new double[length];
        System.arraycopy(array, 0, retVal, start, length);
        return retVal;
    }

    /**
     * Creates a copy of a sub-array of the given array.
     * @param array the array
     * @param start the start index (inclusive) of the sub-array
     * @param length number of elements in the sub-array
     * @return copy of sub-array of the given array.
     */
    public static int[] copyArray(int[] array, int start, int length) {
        int[] retVal = new int[length];
        System.arraycopy(array, 0, retVal, start, length);
        return retVal;
    }

    /**
     * Creates a copy of a sub-array of the given array.
     * @param array the array
     * @param start the start index (inclusive) of the sub-array
     * @param length number of elements in the sub-array
     * @return copy of sub-array of the given array.
     */
    public static boolean[] copyArray(boolean[] array, int start, int length) {
        boolean[] retVal = new boolean[length];
        System.arraycopy(array, 0, retVal, start, length);
        return retVal;
    }
}

Related

  1. copyArray()
  2. copyArray(byte[] dest, int off, byte[] src)
  3. copyArray(byte[] original, int start, int length)
  4. copyArray(byte[] out, byte[] in, int idx)
  5. copyArray(double[] a)
  6. copyArray(double[] src, double[] dest, int len)
  7. copyArray(double[][] d)
  8. copyArray(int[] ar)
  9. copyArray(int[] inArr, int[] outArr)