Java Array Range Copy copyOf(double[] array, int length)

Here you can find the source of copyOf(double[] array, int length)

Description

copy Of

License

Open Source License

Declaration

public static double[] copyOf(double[] array, int length) 

Method Source Code

//package com.java2s;

public class Main {
    public static double[] copyOf(double[] array, int length) {
        double[] result = new double[length];

        int n = Math.min(length, array.length);

        for (int i = 0; i < n; i++) {
            result[i] = array[i];/*from www.j  a v a 2  s. c  o m*/
        }

        return result;
    }

    public static int[] copyOf(int[] array, int length) {
        int[] result = new int[length];

        int n = Math.min(length, array.length);

        for (int i = 0; i < n; i++) {
            result[i] = array[i];
        }

        return result;
    }

    public static float[] copyOf(float[] array, int length) {
        float[] result = new float[length];

        int n = Math.min(length, array.length);

        for (int i = 0; i < n; i++) {
            result[i] = array[i];
        }

        return result;
    }

    public static short[] copyOf(short[] array, int length) {
        short[] result = new short[length];

        int n = Math.min(length, array.length);

        for (int i = 0; i < n; i++) {
            result[i] = array[i];
        }

        return result;
    }

    public static long[] copyOf(long[] array, int length) {
        long[] result = new long[length];

        int n = Math.min(length, array.length);

        for (int i = 0; i < n; i++) {
            result[i] = array[i];
        }

        return result;
    }

    public static boolean[] copyOf(boolean[] array, int length) {
        boolean[] result = new boolean[length];

        int n = Math.min(length, array.length);

        for (int i = 0; i < n; i++) {
            result[i] = array[i];
        }

        return result;
    }

    public static byte[] copyOf(byte[] array, int length) {
        byte[] result = new byte[length];

        int n = Math.min(length, array.length);

        for (int i = 0; i < n; i++) {
            result[i] = array[i];
        }

        return result;
    }

    public static char[] copyOf(char[] array, int length) {
        char[] result = new char[length];

        int n = Math.min(length, array.length);

        for (int i = 0; i < n; i++) {
            result[i] = array[i];
        }

        return result;
    }

    public static Object[] copyOf(Object[] array, int length) {
        Object[] result = new Object[length];

        int n = Math.min(length, array.length);

        for (int i = 0; i < n; i++) {
            result[i] = array[i];
        }

        return result;
    }
}

Related

  1. copyOf(byte[] original, int newLength)
  2. copyOf(byte[] source, int newLength)
  3. copyOf(byte[] src, int length)
  4. copyOf(char[] array)
  5. copyOf(char[] source)
  6. copyOf(double[] v, int newlength)
  7. copyOf(final byte[] bytes)
  8. copyOf(int[] arr)
  9. copyOf(int[] arr, int length)