Java Array Range Copy copyOfRange(int[] old, int from, int to)

Here you can find the source of copyOfRange(int[] old, int from, int to)

Description

Identical to Arrays.copyOfRange , but GWT compatible.

License

Open Source License

Declaration

public static int[] copyOfRange(int[] old, int from, int to) 

Method Source Code

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

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

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

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

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

Related

  1. copyOfRange(char[] original, int from, int to)
  2. copyOfRange(final byte[] array, final int startIndex, final int endIndex)
  3. copyOfRange(final byte[] original, final int from, final int to)
  4. copyOfRange(final double[] data, final int start, final int end)
  5. copyOfRange(int[] anArray, int from, int to)
  6. copyOfRange(int[] original, int from, int to)
  7. copyOfRange(String[] array, int initialIndex, int endIndex)
  8. copyOfRange(String[] original, int from, int newLength)