get sub Array - Android java.lang

Android examples for java.lang:Array Element

Description

get sub Array

Demo Code


//package com.java2s;

import java.lang.reflect.Array;

public class Main {
    public static <M extends Object> M[] subArray(M[] array, int start,
            int end) {
        end = Math.min(array.length, end);
        if (start >= end)
            return null;

        M[] result = (M[]) Array.newInstance(array[0].getClass(), end
                - start);/*w w w  .  ja v a  2 s  .  co m*/
        System.arraycopy(array, start, result, 0, result.length);

        return result;
    }
}

Related Tutorials