Java Reflection Java Java API
java.lang.reflect.Array
public static void setInt(Object array, int index, int i) throws IllegalArgumentException, ArrayIndexOutOfBoundsException
Sets the value of the indexed component of the specified array object to the specified int value.
int
package com.logicbig.example.array;import java.lang.reflect.Array;import java.util.Arrays;public class SetIntExample { public static void main(String... args) { Object o = Array.newInstance(int.class, 3); for (int i = 0; i < 3; i++) { Array.setInt(o, i, i*2); } System.out.println(Arrays.toString((int[]) o)); }}
[0, 2, 4]