public final class Array extends Object
Modifier and Type | Method and Description |
---|---|
static Object |
get(Object array,
int index)
Return the element of the array at the specified index.
|
static boolean |
getBoolean(Object array,
int index)
Return the element of the array at the specified index,
converted to a boolean if possible.
|
static byte |
getByte(Object array,
int index)
Return the element of the array at the specified index,
converted to a byte if possible.
|
static char |
getChar(Object array,
int index)
Return the element of the array at the specified index,
converted to a char if possible.
|
static double |
getDouble(Object array,
int index)
Return the element of the array at the specified index,
converted to a double if possible.
|
static float |
getFloat(Object array,
int index)
Return the element of the array at the specified index,
converted to a float if possible.
|
static int |
getInt(Object array,
int index)
Return the element of the array at the specified index,
converted to an int if possible.
|
static int |
getLength(Object array)
Return the length of the array.
|
static long |
getLong(Object array,
int index)
Return the element of the array at the specified index,
converted to a long if possible.
|
static short |
getShort(Object array,
int index)
Return the element of the array at the specified index,
converted to a short if possible.
|
static Object |
newInstance(Class<?> componentType,
int... dimensions)
Return a new multidimensional array of the specified component type and dimensions.
|
static Object |
newInstance(Class<?> componentType,
int size)
Return a new array of the specified component type and length.
|
static void |
set(Object array,
int index,
Object value)
Set the element of the array at the specified index to the value.
|
static void |
setBoolean(Object array,
int index,
boolean value)
Set the element of the array at the specified index to the boolean
value.
|
static void |
setByte(Object array,
int index,
byte value)
Set the element of the array at the specified index to the byte
value.
|
static void |
setChar(Object array,
int index,
char value)
Set the element of the array at the specified index to the char
value.
|
static void |
setDouble(Object array,
int index,
double value)
Set the element of the array at the specified index to the double
value.
|
static void |
setFloat(Object array,
int index,
float value)
Set the element of the array at the specified index to the float
value.
|
static void |
setInt(Object array,
int index,
int value)
Set the element of the array at the specified index to the int
value.
|
static void |
setLong(Object array,
int index,
long value)
Set the element of the array at the specified index to the long
value.
|
static void |
setShort(Object array,
int index,
short value)
Set the element of the array at the specified index to the short
value.
|
public static Object get(Object array, int index) throws IllegalArgumentException, ArrayIndexOutOfBoundsException
array[index]
If the array component is a base type, the result is
automatically wrapped.array
- the arrayindex
- the indexNullPointerException
- if the array is nullIllegalArgumentException
- if the array is not an arrayArrayIndexOutOfBoundsException
- if the index is out of bounds -- negative or greater than or equal to the array lengthpublic static boolean getBoolean(Object array, int index) throws IllegalArgumentException, ArrayIndexOutOfBoundsException
array[index]
array
- the arrayindex
- the indexNullPointerException
- if the array is nullIllegalArgumentException
- if the array is not an array or the element cannot be converted to the requested type by a widening conversionArrayIndexOutOfBoundsException
- if the index is out of bounds -- negative or greater than or equal to the array lengthpublic static byte getByte(Object array, int index) throws IllegalArgumentException, ArrayIndexOutOfBoundsException
array[index]
array
- the arrayindex
- the indexNullPointerException
- if the array is nullIllegalArgumentException
- if the array is not an array or the element cannot be converted to the requested type by a widening conversionArrayIndexOutOfBoundsException
- if the index is out of bounds -- negative or greater than or equal to the array lengthpublic static char getChar(Object array, int index) throws IllegalArgumentException, ArrayIndexOutOfBoundsException
array[index]
array
- the arrayindex
- the indexNullPointerException
- if the array is nullIllegalArgumentException
- if the array is not an array or the element cannot be converted to the requested type by a widening conversionArrayIndexOutOfBoundsException
- if the index is out of bounds -- negative or greater than or equal to the array lengthpublic static double getDouble(Object array, int index) throws IllegalArgumentException, ArrayIndexOutOfBoundsException
array[index]
array
- the arrayindex
- the indexNullPointerException
- if the array is nullIllegalArgumentException
- if the array is not an array or the element cannot be converted to the requested type by a widening conversionArrayIndexOutOfBoundsException
- if the index is out of bounds -- negative or greater than or equal to the array lengthpublic static float getFloat(Object array, int index) throws IllegalArgumentException, ArrayIndexOutOfBoundsException
array[index]
array
- the arrayindex
- the indexNullPointerException
- if the array is nullIllegalArgumentException
- if the array is not an array or the element cannot be converted to the requested type by a widening conversionArrayIndexOutOfBoundsException
- if the index is out of bounds -- negative or greater than or equal to the array lengthpublic static int getInt(Object array, int index) throws IllegalArgumentException, ArrayIndexOutOfBoundsException
array[index]
array
- the arrayindex
- the indexNullPointerException
- if the array is nullIllegalArgumentException
- if the array is not an array or the element cannot be converted to the requested type by a widening conversionArrayIndexOutOfBoundsException
- if the index is out of bounds -- negative or greater than or equal to the array lengthpublic static int getLength(Object array) throws IllegalArgumentException
array.length
array
- the arrayNullPointerException
- if the array is nullIllegalArgumentException
- if the array is not an arraypublic static long getLong(Object array, int index) throws IllegalArgumentException, ArrayIndexOutOfBoundsException
array[index]
array
- the arrayindex
- the indexNullPointerException
- if the array is nullIllegalArgumentException
- if the array is not an array or the element cannot be converted to the requested type by a widening conversionArrayIndexOutOfBoundsException
- if the index is out of bounds -- negative or greater than or equal to the array lengthpublic static short getShort(Object array, int index) throws IllegalArgumentException, ArrayIndexOutOfBoundsException
array[index]
array
- the arrayindex
- the indexNullPointerException
- if the array is nullIllegalArgumentException
- if the array is not an array or the element cannot be converted to the requested type by a widening conversionArrayIndexOutOfBoundsException
- if the index is out of bounds -- negative or greater than or equal to the array lengthpublic static Object newInstance(Class<?> componentType, int... dimensions) throws NegativeArraySizeException, IllegalArgumentException
new componentType[d0][d1]...[dn]
for a dimensions array of { d0, d1, ... , dn }componentType
- the component type of the new arraydimensions
- the dimensions of the new arrayNullPointerException
- if the component type is nullNegativeArraySizeException
- if any of the dimensions are negativeIllegalArgumentException
- if componentType is Void.TYPE, or if the array of dimensions is of size zero, or exceeds the limit of
the number of dimension for an array (currently 255)public static Object newInstance(Class<?> componentType, int size) throws NegativeArraySizeException
new componentType[size]
componentType
- the component type of the new arraysize
- the length of the new arrayNullPointerException
- if the component type is nullNegativeArraySizeException
- if the size if negativeIllegalArgumentException
- if componentType is Void.TYPE, or the array dimension exceeds the limit of
the number of dimension for an array (currently 255)public static void set(Object array, int index, Object value) throws IllegalArgumentException, ArrayIndexOutOfBoundsException
array[index] = value
If the array component is a base type, the value is automatically
unwrappedarray
- the arrayindex
- the indexvalue
- the new valueNullPointerException
- if the array is nullIllegalArgumentException
- if the array is not an array or the value cannot be converted to the array type by a widening conversionArrayIndexOutOfBoundsException
- if the index is out of bounds -- negative or greater than or equal to the array lengthpublic static void setBoolean(Object array, int index, boolean value) throws IllegalArgumentException, ArrayIndexOutOfBoundsException
array[index] = value
array
- the arrayindex
- the indexvalue
- the new valueNullPointerException
- if the array is nullIllegalArgumentException
- if the array is not an array or the value cannot be converted to the array type by a widening conversionArrayIndexOutOfBoundsException
- if the index is out of bounds -- negative or greater than or equal to the array lengthpublic static void setByte(Object array, int index, byte value) throws IllegalArgumentException, ArrayIndexOutOfBoundsException
array[index] = value
array
- the arrayindex
- the indexvalue
- the new valueNullPointerException
- if the array is nullIllegalArgumentException
- if the array is not an array or the value cannot be converted to the array type by a widening conversionArrayIndexOutOfBoundsException
- if the index is out of bounds -- negative or greater than or equal to the array lengthpublic static void setChar(Object array, int index, char value) throws IllegalArgumentException, ArrayIndexOutOfBoundsException
array[index] = value
array
- the arrayindex
- the indexvalue
- the new valueNullPointerException
- if the array is nullIllegalArgumentException
- if the array is not an array or the value cannot be converted to the array type by a widening conversionArrayIndexOutOfBoundsException
- if the index is out of bounds -- negative or greater than or equal to the array lengthpublic static void setDouble(Object array, int index, double value) throws IllegalArgumentException, ArrayIndexOutOfBoundsException
array[index] = value
array
- the arrayindex
- the indexvalue
- the new valueNullPointerException
- if the array is nullIllegalArgumentException
- if the array is not an array or the value cannot be converted to the array type by a widening conversionArrayIndexOutOfBoundsException
- if the index is out of bounds -- negative or greater than or equal to the array lengthpublic static void setFloat(Object array, int index, float value) throws IllegalArgumentException, ArrayIndexOutOfBoundsException
array[index] = value
array
- the arrayindex
- the indexvalue
- the new valueNullPointerException
- if the array is nullIllegalArgumentException
- if the array is not an array or the value cannot be converted to the array type by a widening conversionArrayIndexOutOfBoundsException
- if the index is out of bounds -- negative or greater than or equal to the array lengthpublic static void setInt(Object array, int index, int value) throws IllegalArgumentException, ArrayIndexOutOfBoundsException
array[index] = value
array
- the arrayindex
- the indexvalue
- the new valueNullPointerException
- if the array is nullIllegalArgumentException
- if the array is not an array or the value cannot be converted to the array type by a widening conversionArrayIndexOutOfBoundsException
- if the index is out of bounds -- negative or greater than or equal to the array lengthpublic static void setLong(Object array, int index, long value) throws IllegalArgumentException, ArrayIndexOutOfBoundsException
array[index] = value
array
- the arrayindex
- the indexvalue
- the new valueNullPointerException
- if the array is nullIllegalArgumentException
- if the array is not an array or the value cannot be converted to the array type by a widening conversionArrayIndexOutOfBoundsException
- if the index is out of bounds -- negative or greater than or equal to the array lengthpublic static void setShort(Object array, int index, short value) throws IllegalArgumentException, ArrayIndexOutOfBoundsException
array[index] = value
array
- the arrayindex
- the indexvalue
- the new valueNullPointerException
- if the array is nullIllegalArgumentException
- if the array is not an array or the value cannot be converted to the array type by a widening conversionArrayIndexOutOfBoundsException
- if the index is out of bounds -- negative or greater than or equal to the array lengthEclipse OpenJ9 website.
To raise a bug report or suggest an improvement create an Eclipse OpenJ9 issue.
Copyright © 1993, 2025 IBM Corp. and others.