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

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

Description

Identical to Arrays.copyOf , but GWT compatible.

License

Open Source License

Declaration

public static int[] copyOf(int[] old, int length) 

Method Source Code

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

public class Main {
    /**/*  w  w  w  . j a  v  a 2s  .c  om*/
     * Identical to {@code Arrays.copyOf}, but GWT compatible.
     */
    public static int[] copyOf(int[] old, int length) {
        int[] newArray = new int[length];
        int minLength = Math.min(old.length, length);
        System.arraycopy(old, 0, newArray, 0, minLength);
        return newArray;
    }

    /**
     * Identical to {@code Arrays.copyOf}, but GWT compatible.
     */
    public static double[] copyOf(double[] old, int length) {
        double[] newArray = new double[length];
        int minLength = Math.min(old.length, length);
        System.arraycopy(old, 0, newArray, 0, minLength);
        return newArray;
    }

    /**
     * Identical to {@code Arrays.copyOf}, but GWT compatible.
     */
    public static long[] copyOf(long[] old, int length) {
        long[] newArray = new long[length];
        int minLength = Math.min(old.length, length);
        System.arraycopy(old, 0, newArray, 0, minLength);
        return newArray;
    }

    /**
     * Identical to {@code Arrays.copyOf}, but GWT compatible.
     */
    public static String[] copyOf(String[] old, int length) {
        String[] newArray = new String[length];
        int minLength = Math.min(old.length, length);
        System.arraycopy(old, 0, newArray, 0, minLength);
        return newArray;
    }

    public static int[][] copyOf(int[][] old) {
        int numRows = old.length;
        int numCols = old[0].length;
        int[][] copy = new int[numRows][numCols];
        for (int i = 0; i < numRows; i++) {
            for (int j = 0; j < numCols; j++) {
                copy[i][j] = old[i][j];
            }
        }
        return copy;
    }
}

Related

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