Set value to an Array

ReturnMethodSummary
static voidset(Object array, int index, Object value)Sets array element to the new value.
static voidsetBoolean(Object array, int index, boolean z)Sets array element to the boolean value.
static voidsetByte(Object array, int index, byte b)Sets array element to the byte value.
static voidsetChar(Object array, int index, char c)Sets array element to the char value.
static voidsetDouble(Object array, int index, double d)Sets array element to the double value.
static voidsetFloat(Object array, int index, float f)Sets array element to the float value.
static voidsetInt(Object array, int index, int i)Sets array element to the int value.
static voidsetLong(Object array, int index, long l)Sets array element to the long value.
static voidsetShort(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));
  }
}
java2s.com  | Contact Us | Privacy Policy
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.