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

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

Description

Returns a copy of given range of given array (this method is in Java 6 Arrays class).

License

Open Source License

Declaration

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

Method Source Code

//package com.java2s;

public class Main {
    /**/*from  w  w  w.  j  a  v  a  2  s.  c om*/
     * Returns a copy of given range of given array (this method is in Java 6 Arrays class).
     */
    public static int[] copyOfRange(int[] anArray, int from, int to) {
        int newLength = to - from;
        if (newLength < 0)
            throw new IllegalArgumentException(from + " > " + to);
        int[] copy = new int[newLength];
        System.arraycopy(anArray, from, copy, 0, Math.min(anArray.length - from, newLength));
        return copy;
    }
}

Related

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