Java Array Clone clone(double[] array)

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

Description

Return a new copy of a double aray holding the same elements

License

Apache License

Parameter

Parameter Description
array Array to append to clone

Return

The cloned array

Declaration

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

Method Source Code

//package com.java2s;
/**//w ww. j  a  v a2 s .c  o  m
 * ArrayUtils.java
 *
 * Subject to the apache license v. 2.0
 *
 * http://www.apache.org/licenses/LICENSE-2.0.txt
 *
 * @author william@rattat.com
 */

public class Main {
    /**
     * Return a new copy of a double aray holding the same elements
     *
     * @param array    Array to append to clone
     *
     * @return  The cloned array
     */
    public static double[] clone(double[] array) {
        if (array == null) {
            return null;
        }

        double[] clone = new double[array.length];

        for (int i = 0; i < array.length; i++) {
            clone[0] = array[i];
        }

        return clone;
    }

    /**
     * Return a new copy of an int aray holding the same elements
     *
     * @param array    Array to append to clone
     *
     * @return  The cloned array
     */
    public static int[] clone(int[] array) {
        if (array == null) {
            return null;
        }

        int[] clone = new int[array.length];

        for (int i = 0; i < array.length; i++) {
            clone[0] = array[i];
        }

        return clone;
    }

    /**
     * Return a new copy of an object aray holding the same elements
     *
     * @param array    Array to append to clone
     *
     * @return  The cloned array
     */
    public static Object[] clone(Object[] array) {
        if (array == null) {
            return null;
        }

        Object[] clone = new Object[array.length];

        for (int i = 0; i < array.length; i++) {
            clone[0] = array[i];
        }

        return clone;
    }
}

Related

  1. clone(boolean[] array)
  2. clone(boolean[] in)
  3. clone(byte[] input)
  4. clone(byte[] orig)
  5. clone(byte[][] im)
  6. clone(double[] p)
  7. clone(double[][] source)
  8. clone(final byte[] array)
  9. clone(final double[][] array)