Skip to content

Most visited

Recently visited

navigation
Added in API level 1

Array

public final class Array
extends Object

java.lang.Object
   ↳ java.lang.reflect.Array


Provides static methods to create and access arrays dynamically.

Summary

Public methods

static Object get(Object array, int index)

Returns the element of the array at the specified index.

static boolean getBoolean(Object array, int index)

Returns the boolean at the given index in the given boolean array.

static byte getByte(Object array, int index)

Returns the byte at the given index in the given byte array.

static char getChar(Object array, int index)

Returns the char at the given index in the given char array.

static double getDouble(Object array, int index)

Returns the double at the given index in the given array.

static float getFloat(Object array, int index)

Returns the float at the given index in the given array.

static int getInt(Object array, int index)

Returns the int at the given index in the given array.

static int getLength(Object array)

Returns the length of the array.

static long getLong(Object array, int index)

Returns the long at the given index in the given array.

static short getShort(Object array, int index)

Returns the short at the given index in the given array.

static Object newInstance(Class<?> componentType, int size)

Returns a new array of the specified component type and length.

static Object newInstance(Class<?> componentType, int... dimensions)

Returns a new multidimensional array of the specified component type and dimensions.

static void set(Object array, int index, Object value)

Sets the element of the array at the specified index to the value.

static void setBoolean(Object array, int index, boolean value)

Sets array[index] = value.

static void setByte(Object array, int index, byte value)

Sets array[index] = value.

static void setChar(Object array, int index, char value)

Sets array[index] = value.

static void setDouble(Object array, int index, double value)

Sets array[index] = value.

static void setFloat(Object array, int index, float value)

Sets array[index] = value.

static void setInt(Object array, int index, int value)

Sets array[index] = value.

static void setLong(Object array, int index, long value)

Sets array[index] = value.

static void setShort(Object array, int index, short value)

Sets array[index] = value.

Inherited methods

From class java.lang.Object

Public methods

get

Added in API level 1
Object get (Object array, 
                int index)

Returns the element of the array at the specified index. Equivalent to array[index]. If the array component is a primitive type, the result is automatically boxed.

Parameters
array Object
index int
Returns
Object
Throws
NullPointerException if array == null
IllegalArgumentException if array is not an array
ArrayIndexOutOfBoundsException if index < 0 || index >= array.length

getBoolean

Added in API level 1
boolean getBoolean (Object array, 
                int index)

Returns the boolean at the given index in the given boolean array.

Parameters
array Object
index int
Returns
boolean
Throws
NullPointerException if array == null
IllegalArgumentException if array is not an array or the element at the index position can not be converted to the return type
ArrayIndexOutOfBoundsException if index < 0 || index >= array.length

getByte

Added in API level 1
byte getByte (Object array, 
                int index)

Returns the byte at the given index in the given byte array.

Parameters
array Object
index int
Returns
byte
Throws
NullPointerException if array == null
IllegalArgumentException if array is not an array or the element at the index position can not be converted to the return type
ArrayIndexOutOfBoundsException if index < 0 || index >= array.length

getChar

Added in API level 1
char getChar (Object array, 
                int index)

Returns the char at the given index in the given char array.

Parameters
array Object
index int
Returns
char
Throws
NullPointerException if array == null
IllegalArgumentException if array is not an array or the element at the index position can not be converted to the return type
ArrayIndexOutOfBoundsException if index < 0 || index >= array.length

getDouble

Added in API level 1
double getDouble (Object array, 
                int index)

Returns the double at the given index in the given array. Applies to byte, char, float, double, int, long, and short arrays.

Parameters
array Object
index int
Returns
double
Throws
NullPointerException if array == null
IllegalArgumentException if array is not an array or the element at the index position can not be converted to the return type
ArrayIndexOutOfBoundsException if index < 0 || index >= array.length

getFloat

Added in API level 1
float getFloat (Object array, 
                int index)

Returns the float at the given index in the given array. Applies to byte, char, float, int, long, and short arrays.

Parameters
array Object
index int
Returns
float
Throws
NullPointerException if array == null
IllegalArgumentException if array is not an array or the element at the index position can not be converted to the return type
ArrayIndexOutOfBoundsException if index < 0 || index >= array.length

getInt

Added in API level 1
int getInt (Object array, 
                int index)

Returns the int at the given index in the given array. Applies to byte, char, int, and short arrays.

Parameters
array Object
index int
Returns
int
Throws
NullPointerException if array == null
IllegalArgumentException if array is not an array or the element at the index position can not be converted to the return type
ArrayIndexOutOfBoundsException if index < 0 || index >= array.length

getLength

Added in API level 1
int getLength (Object array)

Returns the length of the array. Equivalent to array.length.

Parameters
array Object
Returns
int
Throws
NullPointerException if array == null
IllegalArgumentException if array is not an array

getLong

Added in API level 1
long getLong (Object array, 
                int index)

Returns the long at the given index in the given array. Applies to byte, char, int, long, and short arrays.

Parameters
array Object
index int
Returns
long
Throws
NullPointerException if array == null
IllegalArgumentException if array is not an array or the element at the index position can not be converted to the return type
ArrayIndexOutOfBoundsException if index < 0 || index >= array.length

getShort

Added in API level 1
short getShort (Object array, 
                int index)

Returns the short at the given index in the given array. Applies to byte and short arrays.

Parameters
array Object
index int
Returns
short
Throws
NullPointerException if array == null
IllegalArgumentException if array is not an array or the element at the index position can not be converted to the return type
ArrayIndexOutOfBoundsException if index < 0 || index >= array.length

newInstance

Added in API level 1
Object newInstance (Class<?> componentType, 
                int size)

Returns a new array of the specified component type and length. Equivalent to new componentType[size].

Parameters
componentType Class
size int
Returns
Object
Throws
NullPointerException if the component type is null
NegativeArraySizeException if size < 0

newInstance

Added in API level 9
Object newInstance (Class<?> componentType, 
                int... dimensions)

Returns a new multidimensional array of the specified component type and dimensions. Equivalent to new componentType[d0][d1]...[dn] for a dimensions array of { d0, d1, ... , dn }.

Parameters
componentType Class
dimensions int
Returns
Object
Throws
NullPointerException if array == null
NegativeArraySizeException if any of the dimensions are negative
IllegalArgumentException if the array of dimensions is of size zero, or exceeds the limit of the number of dimension for an array (currently 255)

set

Added in API level 1
void set (Object array, 
                int index, 
                Object value)

Sets the element of the array at the specified index to the value. Equivalent to array[index] = value. If the array component is a primitive type, the value is automatically unboxed.

Parameters
array Object
index int
value Object
Throws
NullPointerException if array == null
IllegalArgumentException if array is not an array or the value cannot be converted to the array type by a widening conversion
ArrayIndexOutOfBoundsException if index < 0 || index >= array.length

setBoolean

Added in API level 1
void setBoolean (Object array, 
                int index, 
                boolean value)

Sets array[index] = value. Applies to boolean arrays.

Parameters
array Object
index int
value boolean
Throws
NullPointerException if array == null
IllegalArgumentException if the array is not an array or the value cannot be converted to the array type by a widening conversion
ArrayIndexOutOfBoundsException if index < 0 || index >= array.length

setByte

Added in API level 1
void setByte (Object array, 
                int index, 
                byte value)

Sets array[index] = value. Applies to byte, double, float, int, long, and short arrays.

Parameters
array Object
index int
value byte
Throws
NullPointerException if array == null
IllegalArgumentException if the array is not an array or the value cannot be converted to the array type by a widening conversion
ArrayIndexOutOfBoundsException if index < 0 || index >= array.length

setChar

Added in API level 1
void setChar (Object array, 
                int index, 
                char value)

Sets array[index] = value. Applies to char, double, float, int, and long arrays.

Parameters
array Object
index int
value char
Throws
NullPointerException if array == null
IllegalArgumentException if the array is not an array or the value cannot be converted to the array type by a widening conversion
ArrayIndexOutOfBoundsException if index < 0 || index >= array.length

setDouble

Added in API level 1
void setDouble (Object array, 
                int index, 
                double value)

Sets array[index] = value. Applies to double arrays.

Parameters
array Object
index int
value double
Throws
NullPointerException if array == null
IllegalArgumentException if the array is not an array or the value cannot be converted to the array type by a widening conversion
ArrayIndexOutOfBoundsException if index < 0 || index >= array.length

setFloat

Added in API level 1
void setFloat (Object array, 
                int index, 
                float value)

Sets array[index] = value. Applies to double and float arrays.

Parameters
array Object
index int
value float
Throws
NullPointerException if array == null
IllegalArgumentException if the array is not an array or the value cannot be converted to the array type by a widening conversion
ArrayIndexOutOfBoundsException if index < 0 || index >= array.length

setInt

Added in API level 1
void setInt (Object array, 
                int index, 
                int value)

Sets array[index] = value. Applies to double, float, int, and long arrays.

Parameters
array Object
index int
value int
Throws
NullPointerException if array == null
IllegalArgumentException if the array is not an array or the value cannot be converted to the array type by a widening conversion
ArrayIndexOutOfBoundsException if index < 0 || index >= array.length

setLong

Added in API level 1
void setLong (Object array, 
                int index, 
                long value)

Sets array[index] = value. Applies to double, float, and long arrays.

Parameters
array Object
index int
value long
Throws
NullPointerException if array == null
IllegalArgumentException if the array is not an array or the value cannot be converted to the array type by a widening conversion
ArrayIndexOutOfBoundsException if index < 0 || index >= array.length

setShort

Added in API level 1
void setShort (Object array, 
                int index, 
                short value)

Sets array[index] = value. Applies to double, float, int, long, and short arrays.

Parameters
array Object
index int
value short
Throws
NullPointerException if array == null
IllegalArgumentException if the array is not an array or the value cannot be converted to the array type by a widening conversion
ArrayIndexOutOfBoundsException if index < 0 || index >= array.length
This site uses cookies to store your preferences for site-specific language and display options.

Hooray!

This class requires API level or higher

This doc is hidden because your selected API level for the documentation is . You can change the documentation API level with the selector above the left navigation.

For more information about specifying the API level your app requires, read Supporting Different Platform Versions.