Array

The Array class provides static methods to dynamically create and access Java arrays.

Get the length of an Array

static int getLength(Object array)
Returns the length of the specified array object, as an int.

Get value from an Array

static Object get(Object array, int index)
Returns the value of the indexed component in the specified array object.
static boolean getBoolean(Object array, int index)
Returns array element as a boolean.
static byte getByte(Object array, int index)
Returns array element as a byte.
static char getChar(Object array, int index)
Returns array element as a char.
static double getDouble(Object array, int index)
Returns array element as a double.
static float getFloat(Object array, int index)
Returns array element as a float.
static int getInt(Object array, int index)
Returns array element as an int.
static long getLong(Object array, int index)
Returns array element as a long.
static short getShort(Object array, int index)
Returns array element as a short.

Create new Array instance

static Object newInstance(Class<?> componentType, int... dimensions)
Creates a new array with the component type and dimensions.
static Object newInstance(Class<?> componentType, int length)
Creates a new array with the component type and length.

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.

Revised from Open JDK source code

Home 
  Java Book 
    Reflection  

Array:
  1. Array
  2. Get the length of an Array
  3. Get value from an Array
  4. Create new Array instance
  5. Set value to an Array