List of usage examples for java.lang.reflect Array newInstance
public static Object newInstance(Class<?> componentType, int... dimensions) throws IllegalArgumentException, NegativeArraySizeException
From source file:Main.java
public static void main(String[] argv) throws Exception { int[] ints = (int[]) Array.newInstance(int.class, 10); }
From source file:Main.java
public static void main(String[] argv) throws Exception { int[] ints = (int[]) Array.newInstance(int.class, 10); String[] stringArray = (String[]) Array.newInstance(String.class, 10); }
From source file:MainClass.java
public static void main(String args[]) { Object array = Array.newInstance(int.class, 3); int length = Array.getLength(array); for (int i = 0; i < length; i++) { int value = i; Array.setInt(array, i, value); }//from w ww. jav a 2 s . co m for (int i : (int[]) array) { System.out.println(i); } }
From source file:Main.java
public static void main(String[] argv) throws Exception { int[][] ints2 = (int[][]) Array.newInstance(int.class, new int[] { 10, 20 }); }
From source file:Main.java
public static void main(String[] argv) throws Exception { int[][] ints2 = (int[][]) Array.newInstance(int[].class, 10); }
From source file:MainClass.java
public static void main(String args[]) { int[] array = (int[]) Array.newInstance(int.class, 3); for (int i = 0; i < array.length; i++) { array[i] = i;//from w w w .j av a 2 s. c o m } int[] arrayDoubled = (int[]) doubleArray(array); for (int i : arrayDoubled) { System.out.println(i); } }
From source file:Main.java
public static void main(String[] argv) throws Exception { int[] array = { 1, 2, 3 }; Object newArray = Array.newInstance(array.getClass().getComponentType(), Array.getLength(array) * 2); System.arraycopy(array, 0, newArray, 0, Array.getLength(array)); }
From source file:MainClass.java
public static void main(String args[]) { Object array = Array.newInstance(int.class, 3); printType(array);// ww w. j a v a 2s . co m fillArray(array); displayArray(array); }
From source file:MainClass.java
public static void main(String args[]) { int dimensions[] = { 3, 4 }; int array[][] = (int[][]) Array.newInstance(int.class, dimensions); for (int[] inner : array) { for (int i : inner) { System.out.println(i); }//from ww w.ja va 2 s .co m } }
From source file:MainClass.java
public static void main(String args[]) { Object array = Array.newInstance(int.class, 3); Class type = array.getClass(); if (type.isArray()) { Class elementType = type.getComponentType(); System.out.println("Array of: " + elementType); System.out.println("Array size: " + Array.getLength(array)); }/*from w w w. j a v a2 s . c o m*/ }