All Packages Class Hierarchy This Package Previous Next Index
Class java.lang.reflect.Array
java.lang.Object
|
+----java.lang.reflect.Array
public final class Array
extends Object
The Array class provides static methods to dynamically create and
access Java arrays.
Array permits widening conversions to occur during a get or set
operation, but throws an IllegalArgumentException if a narrowing
conversion would occur.
get (Object, int)
Returns the value of the indexed component in the specified
array object.
getBoolean (Object, int)
Returns the value of the indexed component in the specified
array object, as a boolean.
getByte (Object, int)
Returns the value of the indexed component in the specified
array object, as a byte.
getChar (Object, int)
Returns the value of the indexed component in the specified
array object, as a char.
getDouble (Object, int)
Returns the value of the indexed component in the specified
array object, as a double.
getFloat (Object, int)
Returns the value of the indexed component in the specified
array object, as a float.
getInt (Object, int)
Returns the value of the indexed component in the specified
array object, as an int.
getLength (Object)
Returns the length of the specified array object, as an int.
getLong (Object, int)
Returns the value of the indexed component in the specified
array object, as a long.
getShort (Object, int)
Returns the value of the indexed component in the specified
array object, as a short.
newInstance (Class, int)
Creates a new array with the specified component type and
length.
newInstance (Class, int[])
Creates a new array with the specified component type and
dimensions.
set (Object, int, Object)
Sets the value of the indexed component of the specified array
object to the specified new value.
setBoolean (Object, int, boolean)
Sets the value of the indexed component of the specified array
object to the specified boolean value.
setByte (Object, int, byte)
Sets the value of the indexed component of the specified array
object to the specified boolean value.
setChar (Object, int, char)
Sets the value of the indexed component of the specified array
object to the specified byte value.
setDouble (Object, int, double)
Sets the value of the indexed component of the specified array
object to the specified double value.
setFloat (Object, int, float)
Sets the value of the indexed component of the specified array
object to the specified float value.
setInt (Object, int, int)
Sets the value of the indexed component of the specified array
object to the specified int value.
setLong (Object, int, long)
Sets the value of the indexed component of the specified array
object to the specified long value.
setShort (Object, int, short)
Sets the value of the indexed component of the specified array
object to the specified short value.
newInstance
public static Object newInstance(Class componentType,
int length) throws NegativeArraySizeException
Creates a new array with the specified component type and
length.
The effect is that of the equivalent array creation expression:
new componentType[length]
Parameters:
componentType - the Class object representing the
component type of the new array
length - the length of the new array
Returns:
the new array
Throws: NullPointerException
if the specified
componentType parameter is null
Throws: NegativeArraySizeException
if the specified length
is negative
newInstance
public static Object newInstance(Class componentType,
int dimensions[]) throws IllegalArgumentException , NegativeArraySizeException
Creates a new array with the specified component type and
dimensions.
The effect is that of the equivalent array creation expression:
new componentType[dimensions[0]][dimensions[1]]...
Parameters:
componentType - the Class object representing the component
type of the new array
dimensions - an array of ints representing the dimensions of
the new array
Returns:
the new array
Throws: NullPointerException
if the specified
componentType argument is null
Throws: 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).
Throws: NegativeArraySizeException
if any of the components in
the specified dimension argument is negative.
getLength
public static native int getLength(Object array) throws IllegalArgumentException
Returns the length of the specified array object, as an int.
Parameters:
array - the array
Returns:
the length of the array
Throws: IllegalArgumentException
if the object argument is not
an array
get
public static native Object get(Object array,
int index) throws IllegalArgumentException , ArrayIndexOutOfBoundsException
Returns the value of the indexed component in the specified
array object. The value is automatically wrapped in an object
if it has a primitive type.
Parameters:
array - the array
index - the index
Returns:
the (possibly wrapped) value of the indexed component in
the specified array
Throws: NullPointerException
If the specified object is null
Throws: IllegalArgumentException
If the specified object is not
an array
Throws: ArrayIndexOutOfBoundsException
If the specified index
argument is negative, or if it is greater than or equal to the
length of the specified array
getBoolean
public static native boolean getBoolean(Object array,
int index) throws IllegalArgumentException , ArrayIndexOutOfBoundsException
Returns the value of the indexed component in the specified
array object, as a boolean.
Parameters:
array - the array
index - the index
Returns:
the value of the indexed component in the specified array
Throws: NullPointerException
If the specified object is null
Throws: IllegalArgumentException
If the specified object is not
an array, or if the indexed element cannot be converted to the
return type by an identity or widening conversion
Throws: ArrayIndexOutOfBoundsException
If the specified index
argument is negative, or if it is greater than or equal to the
length of the specified array
See Also:
get
getByte
public static native byte getByte(Object array,
int index) throws IllegalArgumentException , ArrayIndexOutOfBoundsException
Returns the value of the indexed component in the specified
array object, as a byte.
Parameters:
array - the array
index - the index
Returns:
the value of the indexed component in the specified array
Throws: NullPointerException
If the specified object is null
Throws: IllegalArgumentException
If the specified object is not
an array, or if the indexed element cannot be converted to the
return type by an identity or widening conversion
Throws: ArrayIndexOutOfBoundsException
If the specified index
argument is negative, or if it is greater than or equal to the
length of the specified array
See Also:
get
getChar
public static native char getChar(Object array,
int index) throws IllegalArgumentException , ArrayIndexOutOfBoundsException
Returns the value of the indexed component in the specified
array object, as a char.
Parameters:
array - the array
index - the index
Returns:
the value of the indexed component in the specified array
Throws: NullPointerException
If the specified object is null
Throws: IllegalArgumentException
If the specified object is not
an array, or if the indexed element cannot be converted to the
return type by an identity or widening conversion
Throws: ArrayIndexOutOfBoundsException
If the specified index
argument is negative, or if it is greater than or equal to the
length of the specified array
See Also:
get
getShort
public static native short getShort(Object array,
int index) throws IllegalArgumentException , ArrayIndexOutOfBoundsException
Returns the value of the indexed component in the specified
array object, as a short.
Parameters:
array - the array
index - the index
Returns:
the value of the indexed component in the specified array
Throws: NullPointerException
If the specified object is null
Throws: IllegalArgumentException
If the specified object is not
an array, or if the indexed element cannot be converted to the
return type by an identity or widening conversion
Throws: ArrayIndexOutOfBoundsException
If the specified index
argument is negative, or if it is greater than or equal to the
length of the specified array
See Also:
get
getInt
public static native int getInt(Object array,
int index) throws IllegalArgumentException , ArrayIndexOutOfBoundsException
Returns the value of the indexed component in the specified
array object, as an int.
Parameters:
array - the array
index - the index
Returns:
the value of the indexed component in the specified array
Throws: NullPointerException
If the specified object is null
Throws: IllegalArgumentException
If the specified object is not
an array, or if the indexed element cannot be converted to the
return type by an identity or widening conversion
Throws: ArrayIndexOutOfBoundsException
If the specified index
argument is negative, or if it is greater than or equal to the
length of the specified array
See Also:
get
getLong
public static native long getLong(Object array,
int index) throws IllegalArgumentException , ArrayIndexOutOfBoundsException
Returns the value of the indexed component in the specified
array object, as a long.
Parameters:
array - the array
index - the index
Returns:
the value of the indexed component in the specified array
Throws: NullPointerException
If the specified object is null
Throws: IllegalArgumentException
If the specified object is not
an array, or if the indexed element cannot be converted to the
return type by an identity or widening conversion
Throws: ArrayIndexOutOfBoundsException
If the specified index
argument is negative, or if it is greater than or equal to the
length of the specified array
See Also:
get
getFloat
public static native float getFloat(Object array,
int index) throws IllegalArgumentException , ArrayIndexOutOfBoundsException
Returns the value of the indexed component in the specified
array object, as a float.
Parameters:
array - the array
index - the index
Returns:
the value of the indexed component in the specified array
Throws: NullPointerException
If the specified object is null
Throws: IllegalArgumentException
If the specified object is not
an array, or if the indexed element cannot be converted to the
return type by an identity or widening conversion
Throws: ArrayIndexOutOfBoundsException
If the specified index
argument is negative, or if it is greater than or equal to the
length of the specified array
See Also:
get
getDouble
public static native double getDouble(Object array,
int index) throws IllegalArgumentException , ArrayIndexOutOfBoundsException
Returns the value of the indexed component in the specified
array object, as a double.
Parameters:
array - the array
index - the index
Returns:
the value of the indexed component in the specified array
Throws: NullPointerException
If the specified object is null
Throws: IllegalArgumentException
If the specified object is not
an array, or if the indexed element cannot be converted to the
return type by an identity or widening conversion
Throws: ArrayIndexOutOfBoundsException
If the specified index
argument is negative, or if it is greater than or equal to the
length of the specified array
See Also:
get
set
public static native void set(Object array,
int index,
Object value) throws IllegalArgumentException , ArrayIndexOutOfBoundsException
Sets the value of 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.
Parameters:
array - the array
index - the index into the array
value - the new value of the indexed component
Throws: NullPointerException
If the specified object argument
is null, or if the array component type is primitive and the specified
value is null
Throws: IllegalArgumentException
If the specified object argument
is not an array, or if the array component type is primitive and
the specified value cannot be converted to the primitive type by
a combination of unwrapping and identity or widening conversions
Throws: ArrayIndexOutOfBoundsException
If the specified index
argument is negative, or if it is greater than or equal to
the length of the specified array
setBoolean
public static native void setBoolean(Object array,
int index,
boolean z) throws IllegalArgumentException , ArrayIndexOutOfBoundsException
Sets the value of the indexed component of the specified array
object to the specified boolean value.
Parameters:
array - the array
index - the index into the array
value - the new value of the indexed component
Throws: NullPointerException
If the specified object argument
is null
Throws: IllegalArgumentException
If the specified object argument
is not an array, or if the the specified value cannot be converted
to the underlying array's component type by an identity or a
primitive widening widening conversion
Throws: ArrayIndexOutOfBoundsException
If the specified index
argument is negative, or if it is greater than or equal to
the length of the specified array
See Also:
set
setByte
public static native void setByte(Object array,
int index,
byte b) throws IllegalArgumentException , ArrayIndexOutOfBoundsException
Sets the value of the indexed component of the specified array
object to the specified boolean value.
Parameters:
array - the array
index - the index into the array
value - the new value of the indexed component
Throws: NullPointerException
If the specified object argument
is null
Throws: IllegalArgumentException
If the specified object argument
is not an array, or if the the specified value cannot be converted
to the underlying array's component type by an identity or a
primitive widening widening conversion
Throws: ArrayIndexOutOfBoundsException
If the specified index
argument is negative, or if it is greater than or equal to
the length of the specified array
See Also:
set
setChar
public static native void setChar(Object array,
int index,
char c) throws IllegalArgumentException , ArrayIndexOutOfBoundsException
Sets the value of the indexed component of the specified array
object to the specified byte value.
Parameters:
array - the array
index - the index into the array
value - the new value of the indexed component
Throws: NullPointerException
If the specified object argument
is null
Throws: IllegalArgumentException
If the specified object argument
is not an array, or if the the specified value cannot be converted
to the underlying array's component type by an identity or a
primitive widening widening conversion
Throws: ArrayIndexOutOfBoundsException
If the specified index
argument is negative, or if it is greater than or equal to
the length of the specified array
See Also:
set
setShort
public static native void setShort(Object array,
int index,
short s) throws IllegalArgumentException , ArrayIndexOutOfBoundsException
Sets the value of the indexed component of the specified array
object to the specified short value.
Parameters:
array - the array
index - the index into the array
value - the new value of the indexed component
Throws: NullPointerException
If the specified object argument
is null
Throws: IllegalArgumentException
If the specified object argument
is not an array, or if the the specified value cannot be converted
to the underlying array's component type by an identity or a
primitive widening widening conversion
Throws: ArrayIndexOutOfBoundsException
If the specified index
argument is negative, or if it is greater than or equal to
the length of the specified array
See Also:
set
setInt
public static native void setInt(Object array,
int index,
int i) throws IllegalArgumentException , ArrayIndexOutOfBoundsException
Sets the value of the indexed component of the specified array
object to the specified int value.
Parameters:
array - the array
index - the index into the array
value - the new value of the indexed component
Throws: NullPointerException
If the specified object argument
is null
Throws: IllegalArgumentException
If the specified object argument
is not an array, or if the the specified value cannot be converted
to the underlying array's component type by an identity or a
primitive widening widening conversion
Throws: ArrayIndexOutOfBoundsException
If the specified index
argument is negative, or if it is greater than or equal to
the length of the specified array
See Also:
set
setLong
public static native void setLong(Object array,
int index,
long l) throws IllegalArgumentException , ArrayIndexOutOfBoundsException
Sets the value of the indexed component of the specified array
object to the specified long value.
Parameters:
array - the array
index - the index into the array
value - the new value of the indexed component
Throws: NullPointerException
If the specified object argument
is null
Throws: IllegalArgumentException
If the specified object argument
is not an array, or if the the specified value cannot be converted
to the underlying array's component type by an identity or a
primitive widening widening conversion
Throws: ArrayIndexOutOfBoundsException
If the specified index
argument is negative, or if it is greater than or equal to
the length of the specified array
See Also:
set
setFloat
public static native void setFloat(Object array,
int index,
float f) throws IllegalArgumentException , ArrayIndexOutOfBoundsException
Sets the value of the indexed component of the specified array
object to the specified float value.
Parameters:
array - the array
index - the index into the array
value - the new value of the indexed component
Throws: NullPointerException
If the specified object argument
is null
Throws: IllegalArgumentException
If the specified object argument
is not an array, or if the the specified value cannot be converted
to the underlying array's component type by an identity or a
primitive widening widening conversion
Throws: ArrayIndexOutOfBoundsException
If the specified index
argument is negative, or if it is greater than or equal to
the length of the specified array
See Also:
set
setDouble
public static native void setDouble(Object array,
int index,
double d) throws IllegalArgumentException , ArrayIndexOutOfBoundsException
Sets the value of the indexed component of the specified array
object to the specified double value.
Parameters:
array - the array
index - the index into the array
value - the new value of the indexed component
Throws: NullPointerException
If the specified object argument
is null
Throws: IllegalArgumentException
If the specified object argument
is not an array, or if the the specified value cannot be converted
to the underlying array's component type by an identity or a
primitive widening widening conversion
Throws: ArrayIndexOutOfBoundsException
If the specified index
argument is negative, or if it is greater than or equal to
the length of the specified array
See Also:
set
All Packages Class Hierarchy This Package Previous Next Index
Submit a bug or feature