Array: setInt(Object array, int index, int i)
/*
Output:
Position: 0, value: 1040988893
Position: 1, value: -2073064706
Position: 2, value: -808861084
* */
import java.lang.reflect.Array;
import java.util.Random;
public class MainClass {
public static void main (String args[]) {
Object array = Array.newInstance(int.class, 3);
int length = Array.getLength(array);
Random generator = new Random(System.currentTimeMillis());
for (int i=0; i<length; i++) {
int random = generator.nextInt();
Array.setInt(array, i, random);
}
for (int i=0; i<length; i++) {
int value = Array.getInt(array, i);
System.out.println("Position: " + i + ", value: " + value);
}
}
}
Related examples in the same category
1. | Array: clone() | | |
2. | Array: get(Object array, int index) | | |
3. | Array: getInt(Object array, int index) | | |
4. | Array: getLength(Object array) | | |
5. | Array: newInstance(Class componentType, int length) | | |
6. | Array: newInstance(Class> componentType, int... dimensions) | | |
7. | Array: set(Object array, int index, Object value) | | |
8. | Array: setLong(Object array, int index, long l) | | |
9. | Array: setShort(Object array, int index, short s) | | |