Android Array Range Copy copyOfRange(T[] original, int start, int end)

Here you can find the source of copyOfRange(T[] original, int start, int end)

Description

copy Of Range

Declaration

public static <T> T[] copyOfRange(T[] original, int start, int end) 

Method Source Code

//package com.java2s;
import java.lang.reflect.Array;

public class Main {
    public static <T> T[] copyOfRange(T[] original, int start, int end) {
        int originalLength = original.length; // For exception priority compatibility.
        if (start > end) {
            throw new IllegalArgumentException();
        }/* ww w  .  jav  a 2  s.  c  o  m*/
        if (start < 0 || start > originalLength) {
            throw new ArrayIndexOutOfBoundsException();
        }
        int resultLength = end - start;
        int copyLength = Math.min(resultLength, originalLength - start);
        T[] result = (T[]) Array.newInstance(original.getClass()
                .getComponentType(), resultLength);
        System.arraycopy(original, start, result, 0, copyLength);
        return result;
    }
}

Related

  1. copyOfRange(T[] original, int from, int to)
  2. copyOfRange(U[] original, int from, int to, Class newType)
  3. copyOfRange(byte[] original, int from, int to)
  4. copyOfRange(final byte[] source, final int from, final int to)
  5. copyOfRange(final byte[] source, final int from, final int to)