集册 Java实例教程 按大小创建新数组

按大小创建新数组

欢马劈雪     最近更新时间:2020-01-02 10:19:05

388
提示:您可在线编辑运行本教程的实例 - 运行实例,去试试!
按大小创建新数组


//package com.book2s;

import java.lang.reflect.Array;/** 来自 nowjava**/


public class Main {

    public static void main(String[] argv) {

        Class componentType = String.class;

        int newSize = 42;

        System.out.println(java.util.Arrays.toString(newArray(

                componentType, newSize)));

    }


    @SuppressWarnings("unchecked")
    /* from 
    N o w  J a v a  .   c o m*/

    public static <T> T[] newArray(Class<?> component
展开阅读全文