Set value to an Array
static void set(Object array, int index, Object value)
- Sets array element to the new value.
static void setBoolean(Object array, int index, boolean z)
- Sets array element to the boolean value.
static void setByte(Object array, int index, byte b)
- Sets array element to the byte value.
static void setChar(Object array, int index, char c)
- Sets array element to the char value.
static void setDouble(Object array, int index, double d)
- Sets array element to the double value.
static void setFloat(Object array, int index, float f)
- Sets array element to the float value.
static void setInt(Object array, int index, int i)
- Sets array element to the int value.
static void setLong(Object array, int index, long l)
- Sets array element to the long value.
static void setShort(Object array, int index, short s)
- Sets array element to the short value.
import java.lang.reflect.Array;
import java.util.Arrays;
public class Main {
public static void main(String[] argv) throws Exception {
int[] array = { 1, 2, 3 };
// Get the value of the third element.
Object o = Array.get(array, 2);
System.out.println("o:"+o);
// Set the value of the third element.
Array.set(array, 2, 1);
System.out.println(Arrays.toString(array));
}
}
Home
Java Book
Reflection
Java Book
Reflection
Array:
- Array
- Get the length of an Array
- Get value from an Array
- Create new Array instance
- Set value to an Array