Java Reflection Java Java API
Class:
java.lang.reflect.Array
Method:
public static void set(Object array,
int index,
Object value)
throws IllegalArgumentException,
ArrayIndexOutOfBoundsException
Sets the value of the indexed component of the specified array object to the specified new value. The new value is
first automatically unwrapped if the array has a primitive component type.
Examples
package com.logicbig.example.array;
import java.lang.reflect.Array; import java.util.Arrays;
public class SetExample {
public static void main(String... args) { Object o = Array.newInstance(String.class, 3); for (int i = 0; i < 3; i++) { Array.set(o, i, String.valueOf(i)); } System.out.println(Arrays.toString((Object[]) o)); } }
Output[0, 1, 2]
|
|