Array
class Array
kotlin.Any | |
↳ | java.lang.reflect.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? |
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 |
static Byte |
Returns the value of the indexed component in the specified array object, as a |
static Char |
Returns the value of the indexed component in the specified array object, as a |
static Double |
Returns the value of the indexed component in the specified array object, as a |
static Float |
Returns the value of the indexed component in the specified array object, as a |
static Int |
Returns the value of the indexed component in the specified array object, as an |
static Int |
Returns the length of the specified array object, as an |
static Long |
Returns the value of the indexed component in the specified array object, as a |
static Short |
Returns the value of the indexed component in the specified array object, as a |
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 |
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 |
static Unit |
Sets the value of the indexed component of the specified array object to the specified |
static Unit |
Sets the value of the indexed component of the specified array object to the specified |
static Unit |
Sets the value of the indexed component of the specified array object to the specified |
static Unit |
Sets the value of the indexed component of the specified array object to the specified |
static Unit |
Sets the value of the indexed component of the specified array object to the specified |
static Unit |
Sets the value of the indexed component of the specified array object to the specified |
static Unit |
Sets the value of the indexed component of the specified array object to the specified |
Public methods
get
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
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 |
See Also
getByte
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 |
See Also
getChar
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 |
See Also
getDouble
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 |
See Also
getFloat
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 |
See Also
getInt
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 |
See Also
getLength
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
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 |
See Also
getShort
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 |
See Also
newInstance
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
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
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
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 |
See Also
setByte
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 |
See Also
setChar
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 |
See Also
setDouble
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 |
See Also
setFloat
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 |
See Also
setInt
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 |
See Also
setLong
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 |
See Also
setShort
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 |
See Also