copy Array using Arrays.copyOf method - Java Collection Framework

Java examples for Collection Framework:Array Copy

Description

copy Array using Arrays.copyOf method

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" };
        System.out.println(java.util.Arrays.toString(copyArray(arr)));
    }//from www .ja  v a 2s  . com

    public static String[] copyArray(String[] arr) {
        String[] arrNew = Arrays.copyOf(arr, arr.length);
        return arrNew;
    }
}

Related Tutorials