copy Array Range - Java Collection Framework

Java examples for Collection Framework:Array Copy

Description

copy Array Range

Demo Code


//package com.java2s;
import java.util.Arrays;

public class Main {
    public static void main(String[] argv) throws Exception {
        String[] arr = new String[] { "1", "abc", "level", null,
                "java2s.com", "asdf 123" };
        int startIndex = 2;
        int endIndex = 2;
        System.out.println(java.util.Arrays.toString(copyArrayRange(arr,
                startIndex, endIndex)));
    }/*w w  w. ja  v a  2 s. c om*/

    public static String[] copyArrayRange(String[] arr, int startIndex,
            int endIndex) {
        String[] arrNew = Arrays.copyOfRange(arr, startIndex, endIndex);
        return arrNew;
    }
}

Related Tutorials