| Contents | Prev | Next | Java Core Reflection |
Thepackage java.lang.reflect;public final class Array extends Object
Array class is an uninstantiable class that exports static methods to create Java arrays with primitive or class component types, and to get and set array component values.
Returns a new array with the specified component type and length. The array is created as if by the equivalent array creation expression, namely:public static Object newInstance(Class componentType, int length)throws NullPointerException, NegativeArraySizeException
new componentType[length]
The method throws a NullPointerException if the specified componentType argument is null.
The method throws a NegativeArraySizeException if the specified length argument is negative.
Returns a new array with the specified component type and dimensions. The array is created as if by the equivalent array creation expression, namely:public static Object newInstance(Class componentType,int[] dimensions)throws NullPointerException, IllegalArgumentException,NegativeArraySizeException
new componentType[dimensions[0]][dimensions[1]]...
The method throws a NullPointerException if either the componentType argument or the dimensions argument is null.
The method throws an IllegalArgumentException if the specified dimensions argument is a zero-dimensional array, or if the number of requested dimensions exceeds the limit on the number of array dimensions supported by the implementation (typically 255).
The method throws a NegativeArraySizeException if any of the elements of the specified dimensions array is negative.
Returns the length of the specified array.public static int getLength(Object array)throws NullPointerException, IllegalArgumentException
Throws a NullPointerException if the specified object argument is null.
Throws an IllegalArgumentException if the specified object argument is not an array.
Returns the value of the indexed component of the specified array object. The value is automatically wrapped in an object if it has a primitive type.public static Object get(Object array, int index)throws NullPointerException, IllegalArgumentException,ArrayIndexOutOfBoundsException
The operation proceeds as follows:
null, the method throws a NullPointerException.IllegalArgumentException.index argument is negative, or if it is greater than or equal to the length of the specified array, the method throws an ArrayIndexOutOfBoundsException.Array.get are also provided for efficiency; these avoid the final wrapping conversion. They are described below.Returns the value of the indexed element in the specified array object, as apublic static boolean getBoolean(Object array, int index)throws NullPointerException, IllegalArgumentException,ArrayIndexOutOfBoundsException
boolean. See Array.get for the detailed procedure.
If the indexed value is not of type boolean, the method throws an IllegalArgumentException.
Returns the value of the indexed element in the specified array object, as apublic static byte getByte(Object array, int index)throws NullPointerException, IllegalArgumentException,ArrayIndexOutOfBoundsException
byte. See Array.get for the detailed procedure.
If the indexed value is not of type byte, the method throws an IllegalArgumentException.
Returns the value of the indexed element in the specified array object, as apublic static char getChar(Object array, int index)throws NullPointerException, IllegalArgumentException,ArrayIndexOutOfBoundsException
char. See Array.get for the detailed procedure.
If the indexed value is not of type char, the method throws an IllegalArgumentException.
Returns the value of the indexed element in the specified array object, as apublic static short getShort(Object array, int index)throws NullPointerException, IllegalArgumentException,ArrayIndexOutOfBoundsException
short. See Array.get for the detailed procedure.
If the indexed value cannot be converted to a short by an identity or widening conversion, the method throws an IllegalArgumentException.
Returns the value of the indexed element in the specified array object, as anpublic static int getInt(Object array, int index)throws NullPointerException, IllegalArgumentException,ArrayIndexOutOfBoundsException
int. See Array.get for the detailed procedure.
If the indexed value cannot be converted to an int by an identity conversion or a widening conversion, the method throws an IllegalArgumentException.
Returns the value of the indexed element in the specified array object, as apublic static long getLong(Object array, int index)throws NullPointerException, IllegalArgumentException,ArrayIndexOutOfBoundsException
long. See Array.get for the detailed procedure.
If the indexed value cannot be converted to a long by an identity conversion or a widening conversion, the method throws an IllegalArgumentException.
Returns the value of the indexed element in the specified array object, as apublic static float getFloat(Object array, int index)throws NullPointerException, IllegalArgumentException,ArrayIndexOutOfBoundsException
float. See Array.get for the detailed procedure.
If the indexed value cannot be converted to a float by an identity conversion or a widening conversion, the method throws an IllegalArgumentException.
Returns the value of the indexed element in the specified array object, as apublic static double getDouble(Object array, int index)throws NullPointerException, IllegalArgumentException,ArrayIndexOutOfBoundsException
double. See Array.get for the detailed procedure.
If the indexed value cannot be converted to a double by an identity conversion or a widening conversion, the method throws an IllegalArgumentException.
Sets 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.public static void set(Object array, int index, Object value)throws NullPointerException, IllegalArgumentException,ArrayIndexOutOfBoundsException
The operation proceeds as follows:
null, the method throws a NullPointerException. IllegalArgumentException.index argument is negative, or if it is greater than or equal to the length of the specified array, the method throws an ArrayIndexOutOfBoundsException.null, the conversion fails by throwing a NullPointerException. If the object parameter is not an instance of a standard Java wrapper class, the conversion fails by throwing an IllegalArgumentException.IllegalArgumentException.Array.set are also provided for efficiency; these let user code avoid having to wrap the new value. They are described below.Sets the indexed element of the specified array object to the specifiedpublic static void setBoolean(Object array, int index, boolean z)throws NullPointerException, IllegalArgumentException,ArrayIndexOutOfBoundsException
boolean value. See Array.set for the detailed procedure.Sets the indexed element of the specified array object to the specifiedpublic static void setByte(Object array, int index, byte b)throws NullPointerException, IllegalArgumentException,ArrayIndexOutOfBoundsException
byte value. See Array.set for the detailed procedure.Sets the indexed element of the specified array object to the specifiedpublic static void setChar(Object array, int index, char c)throws NullPointerException, IllegalArgumentException,ArrayIndexOutOfBoundsException
char value. See Array.set for the detailed procedure.Sets the indexed component of the specified array object to the specifiedpublic static void setShort(Object array, int index, short s)throws NullPointerException, IllegalArgumentException,ArrayIndexOutOfBoundsException
short value. See Array.set for the detailed procedure.Sets the indexed component of the specified array object to the specifiedpublic static void setInt(Object array, int index, int i)throws NullPointerException, IllegalArgumentException,ArrayIndexOutOfBoundsException
int value. See Array.set for the detailed procedure.Sets the indexed component of the specified array object to the specifiedpublic static void setLong(Object array, int index, long l)throws NullPointerException, IllegalArgumentException,ArrayIndexOutOfBoundsException
long value. See Array.set for the detailed procedure.Sets the indexed component of the specified array object to the specifiedpublic static void setFloat(Object array, int index, float f)throws NullPointerException, IllegalArgumentException,ArrayIndexOutOfBoundsException
float value. See Array.set for the detailed procedure.Sets the indexed component of the specified array object to the specifiedpublic static void setDouble(Object array, int index, double d)throws NullPointerException, IllegalArgumentException,ArrayIndexOutOfBoundsException
double value. See Array.set for the detailed procedure.