Top Description Constructors Methods
java.lang.reflect

public final Class Array

extends Object
Class Inheritance
Imports
jdk.internal.vm.annotation.IntrinsicCandidate

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.

Author
Nakul Saraiya
Since
1.1

Constructor Summary

AccessConstructor and Description
private
Array()

Constructor.

Method Summary

Modifier and TypeMethod and Description
public static native Object

Returns:

the (possibly wrapped) value of the indexed component in the specified array
get
(Object
the array
array
,
int
the index
index
)

Returns the value of the indexed component in the specified array object.

public static native boolean

Returns:

the value of the indexed component in the specified array
getBoolean
(Object
the array
array
,
int
the index
index
)

Returns the value of the indexed component in the specified array object, as a boolean.

public static native byte

Returns:

the value of the indexed component in the specified array
getByte
(Object
the array
array
,
int
the index
index
)

Returns the value of the indexed component in the specified array object, as a byte.

public static native char

Returns:

the value of the indexed component in the specified array
getChar
(Object
the array
array
,
int
the index
index
)

Returns the value of the indexed component in the specified array object, as a char.

public static native double

Returns:

the value of the indexed component in the specified array
getDouble
(Object
the array
array
,
int
the index
index
)

Returns the value of the indexed component in the specified array object, as a double.

public static native float

Returns:

the value of the indexed component in the specified array
getFloat
(Object
the array
array
,
int
the index
index
)

Returns the value of the indexed component in the specified array object, as a float.

public static native int

Returns:

the value of the indexed component in the specified array
getInt
(Object
the array
array
,
int
the index
index
)

Returns the value of the indexed component in the specified array object, as an int.

public static native int

Returns:

the length of the array
getLength
(Object
the array
array
)

Returns the length of the specified array object, as an int.

public static native long

Returns:

the value of the indexed component in the specified array
getLong
(Object
the array
array
,
int
the index
index
)

Returns the value of the indexed component in the specified array object, as a long.

public static native short

Returns:

the value of the indexed component in the specified array
getShort
(Object
the array
array
,
int
the index
index
)

Returns the value of the indexed component in the specified array object, as a short.

private static native Object
multiNewArray(Class<?> componentType, int[] dimensions)

private static native Object
newArray(Class<?> componentType, int length)

public static Object

Returns:

the new array
newInstance
(Class<?>
the Class object representing the component type of the new array
componentType
,
int
the length of the new array
length
)

Creates a new array with the specified component type and length.

public static Object

Returns:

the new array
newInstance
(Class<?>
the Class object representing the component type of the new array
componentType
,
int...
an array of int representing the dimensions of the new array
dimensions
)

Creates a new array with the specified component type and dimensions.

public static native void
set(Object
the array
array
,
int
the index into the array
index
,
Object
the new value of the indexed component
value
)

Sets the value of the indexed component of the specified array object to the specified new value.

public static native void
setBoolean(Object
the array
array
,
int
the index into the array
index
,
boolean
the new value of the indexed component
z
)

Sets the value of the indexed component of the specified array object to the specified boolean value.

public static native void
setByte(Object
the array
array
,
int
the index into the array
index
,
byte
the new value of the indexed component
b
)

Sets the value of the indexed component of the specified array object to the specified byte value.

public static native void
setChar(Object
the array
array
,
int
the index into the array
index
,
char
the new value of the indexed component
c
)

Sets the value of the indexed component of the specified array object to the specified char value.

public static native void
setDouble(Object
the array
array
,
int
the index into the array
index
,
double
the new value of the indexed component
d
)

Sets the value of the indexed component of the specified array object to the specified double value.

public static native void
setFloat(Object
the array
array
,
int
the index into the array
index
,
float
the new value of the indexed component
f
)

Sets the value of the indexed component of the specified array object to the specified float value.

public static native void
setInt(Object
the array
array
,
int
the index into the array
index
,
int
the new value of the indexed component
i
)

Sets the value of the indexed component of the specified array object to the specified int value.

public static native void
setLong(Object
the array
array
,
int
the index into the array
index
,
long
the new value of the indexed component
l
)

Sets the value of the indexed component of the specified array object to the specified long value.

public static native void
setShort(Object
the array
array
,
int
the index into the array
index
,
short
the new value of the indexed component
s
)

Sets the value of the indexed component of the specified array object to the specified short value.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Constructor Detail

Arrayback to summary
private Array()

Constructor. Class Array is not instantiable.

Method Detail

getback to summary
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:Object

the array

index:int

the index

Returns:Object

the (possibly wrapped) value of the indexed component in the specified array

Exceptions
IllegalArgumentException:
If the specified object is not an array
ArrayIndexOutOfBoundsException:
If the specified index argument is negative, or if it is greater than or equal to the length of the specified array
NullPointerException:
If the specified object is null
getBooleanback to summary
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:Object

the array

index:int

the index

Returns:boolean

the value of the indexed component in the specified array

Exceptions
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
ArrayIndexOutOfBoundsException:
If the specified index argument is negative, or if it is greater than or equal to the length of the specified array
NullPointerException:
If the specified object is null
See Also
Array#get
getByteback to summary
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:Object

the array

index:int

the index

Returns:byte

the value of the indexed component in the specified array

Exceptions
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
ArrayIndexOutOfBoundsException:
If the specified index argument is negative, or if it is greater than or equal to the length of the specified array
NullPointerException:
If the specified object is null
See Also
Array#get
getCharback to summary
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:Object

the array

index:int

the index

Returns:char

the value of the indexed component in the specified array

Exceptions
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
ArrayIndexOutOfBoundsException:
If the specified index argument is negative, or if it is greater than or equal to the length of the specified array
NullPointerException:
If the specified object is null
See Also
Array#get
getDoubleback to summary
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:Object

the array

index:int

the index

Returns:double

the value of the indexed component in the specified array

Exceptions
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
ArrayIndexOutOfBoundsException:
If the specified index argument is negative, or if it is greater than or equal to the length of the specified array
NullPointerException:
If the specified object is null
See Also
Array#get
getFloatback to summary
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:Object

the array

index:int

the index

Returns:float

the value of the indexed component in the specified array

Exceptions
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
ArrayIndexOutOfBoundsException:
If the specified index argument is negative, or if it is greater than or equal to the length of the specified array
NullPointerException:
If the specified object is null
See Also
Array#get
getIntback to summary
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:Object

the array

index:int

the index

Returns:int

the value of the indexed component in the specified array

Exceptions
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
ArrayIndexOutOfBoundsException:
If the specified index argument is negative, or if it is greater than or equal to the length of the specified array
NullPointerException:
If the specified object is null
See Also
Array#get
getLengthback to summary
public static native int getLength(Object array) throws IllegalArgumentException

Returns the length of the specified array object, as an int.

Parameters
array:Object

the array

Returns:int

the length of the array

Annotations
@IntrinsicCandidate
Exceptions
IllegalArgumentException:
if the object argument is not an array
getLongback to summary
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:Object

the array

index:int

the index

Returns:long

the value of the indexed component in the specified array

Exceptions
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
ArrayIndexOutOfBoundsException:
If the specified index argument is negative, or if it is greater than or equal to the length of the specified array
NullPointerException:
If the specified object is null
See Also
Array#get
getShortback to summary
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:Object

the array

index:int

the index

Returns:short

the value of the indexed component in the specified array

Exceptions
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
ArrayIndexOutOfBoundsException:
If the specified index argument is negative, or if it is greater than or equal to the length of the specified array
NullPointerException:
If the specified object is null
See Also
Array#get
multiNewArrayback to summary
private static native Object multiNewArray(Class<?> componentType, int[] dimensions) throws IllegalArgumentException, NegativeArraySizeException
newArrayback to summary
private static native Object newArray(Class<?> componentType, int length) throws NegativeArraySizeException
Annotations
@IntrinsicCandidate
newInstanceback to summary
public static Object newInstance(Class<?> componentType, int length) throws NegativeArraySizeException

Creates a new array with the specified component type and length.

Implementation Specification

Invoking this method is equivalent to creating an array as follows:

Array.newInstance(componentType, new int[]{length});

The number of dimensions of the new array must not exceed 255.

Parameters
componentType:Class<?>

the Class object representing the component type of the new array

length:int

the length of the new array

Returns:Object

the new array

Exceptions
NegativeArraySizeException:
if the specified length is negative
NullPointerException:
if the specified componentType parameter is null
IllegalArgumentException:
if componentType is Void#TYPE or if the number of dimensions of the requested array instance exceed 255.
newInstanceback to summary
public static Object newInstance(Class<?> componentType, int... dimensions) throws IllegalArgumentException, NegativeArraySizeException

Creates a new array with the specified component type and dimensions. If componentType represents a non-array class or interface, the new array has dimensions.length dimensions and componentType as its component type. If componentType represents an array class, the number of dimensions of the new array is equal to the sum of dimensions.length and the number of dimensions of componentType. In this case, the component type of the new array is the component type of componentType.

The number of dimensions of the new array must not exceed 255.

Parameters
componentType:Class<?>

the Class object representing the component type of the new array

dimensions:int[]

an array of int representing the dimensions of the new array

Returns:Object

the new array

Exceptions
IllegalArgumentException:
if the specified dimensions argument is a zero-dimensional array, if componentType is Void#TYPE, or if the number of dimensions of the requested array instance exceed 255.
NegativeArraySizeException:
if any of the components in the specified dimensions argument is negative.
NullPointerException:
if the specified componentType argument is null
setback to summary
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:Object

the array

index:int

the index into the array

value:Object

the new value of the indexed component

Exceptions
IllegalArgumentException:
If the specified object argument is not an array, or if the array component type is primitive and an unwrapping conversion fails
ArrayIndexOutOfBoundsException:
If the specified index argument is negative, or if it is greater than or equal to the length of the specified array
NullPointerException:
If the specified object argument is null
setBooleanback to summary
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:Object

the array

index:int

the index into the array

z:boolean

the new value of the indexed component

Exceptions
IllegalArgumentException:
If the specified object argument is not an array, or if the specified value cannot be converted to the underlying array's component type by an identity or a primitive widening conversion
ArrayIndexOutOfBoundsException:
If the specified index argument is negative, or if it is greater than or equal to the length of the specified array
NullPointerException:
If the specified object argument is null
See Also
Array#set
setByteback to summary
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 byte value.

Parameters
array:Object

the array

index:int

the index into the array

b:byte

the new value of the indexed component

Exceptions
IllegalArgumentException:
If the specified object argument is not an array, or if the specified value cannot be converted to the underlying array's component type by an identity or a primitive widening conversion
ArrayIndexOutOfBoundsException:
If the specified index argument is negative, or if it is greater than or equal to the length of the specified array
NullPointerException:
If the specified object argument is null
See Also
Array#set
setCharback to summary
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 char value.

Parameters
array:Object

the array

index:int

the index into the array

c:char

the new value of the indexed component

Exceptions
IllegalArgumentException:
If the specified object argument is not an array, or if the specified value cannot be converted to the underlying array's component type by an identity or a primitive widening conversion
ArrayIndexOutOfBoundsException:
If the specified index argument is negative, or if it is greater than or equal to the length of the specified array
NullPointerException:
If the specified object argument is null
See Also
Array#set
setDoubleback to summary
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:Object

the array

index:int

the index into the array

d:double

the new value of the indexed component

Exceptions
IllegalArgumentException:
If the specified object argument is not an array, or if the specified value cannot be converted to the underlying array's component type by an identity or a primitive widening conversion
ArrayIndexOutOfBoundsException:
If the specified index argument is negative, or if it is greater than or equal to the length of the specified array
NullPointerException:
If the specified object argument is null
See Also
Array#set
setFloatback to summary
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:Object

the array

index:int

the index into the array

f:float

the new value of the indexed component

Exceptions
IllegalArgumentException:
If the specified object argument is not an array, or if the specified value cannot be converted to the underlying array's component type by an identity or a primitive widening conversion
ArrayIndexOutOfBoundsException:
If the specified index argument is negative, or if it is greater than or equal to the length of the specified array
NullPointerException:
If the specified object argument is null
See Also
Array#set
setIntback to summary
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:Object

the array

index:int

the index into the array

i:int

the new value of the indexed component

Exceptions
IllegalArgumentException:
If the specified object argument is not an array, or if the specified value cannot be converted to the underlying array's component type by an identity or a primitive widening conversion
ArrayIndexOutOfBoundsException:
If the specified index argument is negative, or if it is greater than or equal to the length of the specified array
NullPointerException:
If the specified object argument is null
See Also
Array#set
setLongback to summary
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:Object

the array

index:int

the index into the array

l:long

the new value of the indexed component

Exceptions
IllegalArgumentException:
If the specified object argument is not an array, or if the specified value cannot be converted to the underlying array's component type by an identity or a primitive widening conversion
ArrayIndexOutOfBoundsException:
If the specified index argument is negative, or if it is greater than or equal to the length of the specified array
NullPointerException:
If the specified object argument is null
See Also
Array#set
setShortback to summary
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:Object

the array

index:int

the index into the array

s:short

the new value of the indexed component

Exceptions
IllegalArgumentException:
If the specified object argument is not an array, or if the specified value cannot be converted to the underlying array's component type by an identity or a primitive widening conversion
ArrayIndexOutOfBoundsException:
If the specified index argument is negative, or if it is greater than or equal to the length of the specified array
NullPointerException:
If the specified object argument is null
See Also
Array#set