Added in API level 1

Array

class Array

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.

Summary

Public methods
static Any?
get(array: Any, index: Int)

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

static Boolean
getBoolean(array: Any, index: Int)

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

static Byte
getByte(array: Any, index: Int)

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

static Char
getChar(array: Any, index: Int)

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

static Double
getDouble(array: Any, index: Int)

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

static Float
getFloat(array: Any, index: Int)

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

static Int
getInt(array: Any, index: Int)

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

static Int
getLength(array: Any)

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

static Long
getLong(array: Any, index: Int)

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

static Short
getShort(array: Any, index: Int)

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

static Any
newInstance(componentType: Class<*>, length: Int)

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

static Any
newInstance(componentType: Class<*>, vararg dimensions: Int)

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

static Unit
set(array: Any, index: Int, value: Any?)

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

static Unit
setBoolean(array: Any, index: Int, z: Boolean)

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

static Unit
setByte(array: Any, index: Int, b: Byte)

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

static Unit
setChar(array: Any, index: Int, c: Char)

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

static Unit
setDouble(array: Any, index: Int, d: Double)

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

static Unit
setFloat(array: Any, index: Int, f: Float)

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

static Unit
setInt(array: Any, index: Int, i: Int)

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

static Unit
setLong(array: Any, index: Int, l: Long)

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

static Unit
setShort(array: Any, index: Int, s: Short)

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

Public methods

get

Added in API level 1
static fun get(
    array: Any,
    index: Int
): Any?

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 Any: the array
index Int: the index
Return
Any? the (possibly wrapped) value of the indexed component in the specified array
Exceptions
java.lang.NullPointerException If the specified object is null
java.lang.IllegalArgumentException If the specified object is not an array
java.lang.ArrayIndexOutOfBoundsException If the specified index argument is negative, or if it is greater than or equal to the length of the specified array

getBoolean

Added in API level 1
static fun getBoolean(
    array: Any,
    index: Int
): Boolean

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

Parameters
array Any: the array
index Int: the index
Return
Boolean the value of the indexed component in the specified array
Exceptions
java.lang.NullPointerException If the specified object is null
java.lang.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
java.lang.ArrayIndexOutOfBoundsException If the specified index argument is negative, or if it is greater than or equal to the length of the specified array

getByte

Added in API level 1
static fun getByte(
    array: Any,
    index: Int
): Byte

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

Parameters
array Any: the array
index Int: the index
Return
Byte the value of the indexed component in the specified array
Exceptions
java.lang.NullPointerException If the specified object is null
java.lang.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
java.lang.ArrayIndexOutOfBoundsException If the specified index argument is negative, or if it is greater than or equal to the length of the specified array

getChar

Added in API level 1
static fun getChar(
    array: Any,
    index: Int
): Char

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

Parameters
array Any: the array
index Int: the index
Return
Char the value of the indexed component in the specified array
Exceptions
java.lang.NullPointerException If the specified object is null
java.lang.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
java.lang.ArrayIndexOutOfBoundsException If the specified index argument is negative, or if it is greater than or equal to the length of the specified array

getDouble

Added in API level 1
static fun getDouble(
    array: Any,
    index: Int
): Double

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

Parameters
array Any: the array
index Int: the index
Return
Double the value of the indexed component in the specified array
Exceptions
java.lang.NullPointerException If the specified object is null
java.lang.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
java.lang.ArrayIndexOutOfBoundsException If the specified index argument is negative, or if it is greater than or equal to the length of the specified array

getFloat

Added in API level 1
static fun getFloat(
    array: Any,
    index: Int
): Float

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

Parameters
array Any: the array
index Int: the index
Return
Float the value of the indexed component in the specified array
Exceptions
java.lang.NullPointerException If the specified object is null
java.lang.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
java.lang.ArrayIndexOutOfBoundsException If the specified index argument is negative, or if it is greater than or equal to the length of the specified array

getInt

Added in API level 1
static fun getInt(
    array: Any,
    index: Int
): Int

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

Parameters
array Any: the array
index Int: the index
Return
Int the value of the indexed component in the specified array
Exceptions
java.lang.NullPointerException If the specified object is null
java.lang.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
java.lang.ArrayIndexOutOfBoundsException If the specified index argument is negative, or if it is greater than or equal to the length of the specified array

getLength

Added in API level 1
static fun getLength(array: Any): Int

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

Parameters
array Any: the array
Return
Int the length of the array
Exceptions
java.lang.IllegalArgumentException if the object argument is not an array

getLong

Added in API level 1
static fun getLong(
    array: Any,
    index: Int
): Long

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

Parameters
array Any: the array
index Int: the index
Return
Long the value of the indexed component in the specified array
Exceptions
java.lang.NullPointerException If the specified object is null
java.lang.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
java.lang.ArrayIndexOutOfBoundsException If the specified index argument is negative, or if it is greater than or equal to the length of the specified array

getShort

Added in API level 1
static fun getShort(
    array: Any,
    index: Int
): Short

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

Parameters
array Any: the array
index Int: the index
Return
Short the value of the indexed component in the specified array
Exceptions
java.lang.NullPointerException If the specified object is null
java.lang.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
java.lang.ArrayIndexOutOfBoundsException If the specified index argument is negative, or if it is greater than or equal to the length of the specified array

newInstance

Added in API level 1
static fun newInstance(
    componentType: Class<*>,
    length: Int
): Any

Creates a new array with the specified component type and length. Invoking this method is equivalent to creating an array as follows:

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

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
Return
Any the new array
Exceptions
java.lang.NullPointerException if the specified componentType parameter is null
java.lang.IllegalArgumentException if componentType is java.lang.Void#TYPE or if the number of dimensions of the requested array instance exceed 255.
java.lang.NegativeArraySizeException if the specified length is negative

newInstance

Added in API level 1
static fun newInstance(
    componentType: Class<*>,
    vararg dimensions: Int
): Any

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

set

Added in API level 1
static fun set(
    array: Any,
    index: Int,
    value: Any?
): Unit

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 Any: the array
index Int: the index into the array
value Any?: the new value of the indexed component
Exceptions
java.lang.NullPointerException If the specified object argument is null
java.lang.IllegalArgumentException If the specified object argument is not an array, or if the array component type is primitive and an unwrapping conversion fails
java.lang.ArrayIndexOutOfBoundsException If the specified index argument is negative, or if it is greater than or equal to the length of the specified array

setBoolean

Added in API level 1
static fun setBoolean(
    array: Any,
    index: Int,
    z: Boolean
): Unit

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

Parameters
array Any: the array
index Int: the index into the array
z Boolean: the new value of the indexed component
Exceptions
java.lang.NullPointerException If the specified object argument is null
java.lang.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
java.lang.ArrayIndexOutOfBoundsException If the specified index argument is negative, or if it is greater than or equal to the length of the specified array

setByte

Added in API level 1
static fun setByte(
    array: Any,
    index: Int,
    b: Byte
): Unit

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

Parameters
array Any: the array
index Int: the index into the array
b Byte: the new value of the indexed component
Exceptions
java.lang.NullPointerException If the specified object argument is null
java.lang.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
java.lang.ArrayIndexOutOfBoundsException If the specified index argument is negative, or if it is greater than or equal to the length of the specified array

setChar

Added in API level 1
static fun setChar(
    array: Any,
    index: Int,
    c: Char
): Unit

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

Parameters
array Any: the array
index Int: the index into the array
c Char: the new value of the indexed component
Exceptions
java.lang.NullPointerException If the specified object argument is null
java.lang.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
java.lang.ArrayIndexOutOfBoundsException If the specified index argument is negative, or if it is greater than or equal to the length of the specified array

setDouble

Added in API level 1
static fun setDouble(
    array: Any,
    index: Int,
    d: Double
): Unit

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

Parameters
array Any: the array
index Int: the index into the array
d Double: the new value of the indexed component
Exceptions
java.lang.NullPointerException If the specified object argument is null
java.lang.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
java.lang.ArrayIndexOutOfBoundsException If the specified index argument is negative, or if it is greater than or equal to the length of the specified array

setFloat

Added in API level 1
static fun setFloat(
    array: Any,
    index: Int,
    f: Float
): Unit

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

Parameters
array Any: the array
index Int: the index into the array
f Float: the new value of the indexed component
Exceptions
java.lang.NullPointerException If the specified object argument is null
java.lang.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
java.lang.ArrayIndexOutOfBoundsException If the specified index argument is negative, or if it is greater than or equal to the length of the specified array

setInt

Added in API level 1
static fun setInt(
    array: Any,
    index: Int,
    i: Int
): Unit

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

Parameters
array Any: the array
index Int: the index into the array
i Int: the new value of the indexed component
Exceptions
java.lang.NullPointerException If the specified object argument is null
java.lang.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
java.lang.ArrayIndexOutOfBoundsException If the specified index argument is negative, or if it is greater than or equal to the length of the specified array

setLong

Added in API level 1
static fun setLong(
    array: Any,
    index: Int,
    l: Long
): Unit

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

Parameters
array Any: the array
index Int: the index into the array
l Long: the new value of the indexed component
Exceptions
java.lang.NullPointerException If the specified object argument is null
java.lang.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
java.lang.ArrayIndexOutOfBoundsException If the specified index argument is negative, or if it is greater than or equal to the length of the specified array

setShort

Added in API level 1
static fun setShort(
    array: Any,
    index: Int,
    s: Short
): Unit

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

Parameters
array Any: the array
index Int: the index into the array
s Short: the new value of the indexed component
Exceptions
java.lang.NullPointerException If the specified object argument is null
java.lang.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
java.lang.ArrayIndexOutOfBoundsException If the specified index argument is negative, or if it is greater than or equal to the length of the specified array