Java examples for Collection Framework:Array Length
Create new Array by size
//package com.book2s; import java.lang.reflect.Array; 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))); }//from www .j av a 2s . co m @SuppressWarnings("unchecked") public static <T> T[] newArray(Class<?> componentType, int newSize) { return (T[]) Array.newInstance(componentType, newSize); } }