copy Of Range in an array - Android java.lang

Android examples for java.lang:array copy

Description

copy Of Range in an array

Demo Code

import java.lang.reflect.Array;
import java.util.List;

public class Main{


    public static int[] copyOfRange(int[] original, int start, int end) {
        if (start <= end) {
            if (original.length >= start && 0 <= start) {
                int length = end - start;
                int copyLength = Math.min(length, original.length - start);
                int[] copy = new int[length];
                System.arraycopy(original, start, copy, 0, copyLength);
                return copy;
            }//from  ww  w  . ja va2 s.  c  om
            throw new ArrayIndexOutOfBoundsException();
        }
        throw new IllegalArgumentException();
    }

}

Related Tutorials