Most visited

Recently visited

Added in API level 1

Array

public final class Array
extends Object

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


Array类提供静态方法来动态创建和访问Java数组。

Array允许在获取或设置操作期间扩展转换,但如果发生缩小转换则抛出 IllegalArgumentException

Summary

Public methods

static Object get(Object array, int index)

返回指定数组对象中索引组件的值。

static boolean getBoolean(Object array, int index)

boolean返回指定数组对象中索引组件的值。

static byte getByte(Object array, int index)

byte返回指定数组对象中索引组件的值。

static char getChar(Object array, int index)

char返回指定数组对象中索引组件的值。

static double getDouble(Object array, int index)

double返回指定数组对象中索引组件的值。

static float getFloat(Object array, int index)

返回指定数组对象中索引组件的值,如 float

static int getInt(Object array, int index)

int返回指定数组对象中索引组件的值。

static int getLength(Object array)

int返回指定数组对象的 int

static long getLong(Object array, int index)

long返回指定数组对象中索引组件的值。

static short getShort(Object array, int index)

short返回指定数组对象中索引组件的值。

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

用指定的组件类型和长度创建一个新数组。

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

用指定的组件类型和尺寸创建一个新数组。

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

将指定数组对象的索引组件的值设置为指定的新值。

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

将指定数组对象的索引组件的值设置为指定的 boolean值。

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

将指定数组对象的索引组件的值设置为指定的 byte值。

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

将指定数组对象的索引组件的值设置为指定的 char值。

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

将指定数组对象的索引组件的值设置为指定的 double值。

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

将指定数组对象的索引组件的值设置为指定的 float值。

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

将指定数组对象的索引组件的值设置为指定的 int值。

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

将指定数组对象的索引组件的值设置为指定的 long值。

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

将指定数组对象的索引组件的值设置为指定的 short值。

Inherited methods

From class java.lang.Object

Public methods

get

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

返回指定数组对象中索引组件的值。 如果该对象具有基本类型,则该值将自动包装在对象中。

Parameters
array Object: the array
index int: the index
Returns
Object the (possibly wrapped) value of the indexed component in the specified array
Throws
NullPointerException If the specified object is null
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

getBoolean

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

boolean返回指定数组对象中索引组件的值。

Parameters
array Object: the array
index int: the index
Returns
boolean the value of the indexed component in the specified array
Throws
NullPointerException If the specified object is null
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

也可以看看:

getByte

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

byte返回指定数组对象中索引组件的值。

Parameters
array Object: the array
index int: the index
Returns
byte the value of the indexed component in the specified array
Throws
NullPointerException If the specified object is null
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

也可以看看:

getChar

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

char返回指定数组对象中索引组件的值。

Parameters
array Object: the array
index int: the index
Returns
char the value of the indexed component in the specified array
Throws
NullPointerException If the specified object is null
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

也可以看看:

getDouble

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

返回指定数组对象中索引组件的值,如 double

Parameters
array Object: the array
index int: the index
Returns
double the value of the indexed component in the specified array
Throws
NullPointerException If the specified object is null
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

也可以看看:

getFloat

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

float返回指定数组对象中索引组件的值。

Parameters
array Object: the array
index int: the index
Returns
float the value of the indexed component in the specified array
Throws
NullPointerException If the specified object is null
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

也可以看看:

getInt

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

int返回指定数组对象中索引组件的值。

Parameters
array Object: the array
index int: the index
Returns
int the value of the indexed component in the specified array
Throws
NullPointerException If the specified object is null
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

也可以看看:

getLength

Added in API level 1
int getLength (Object array)

int返回指定数组对象的 int

Parameters
array Object: the array
Returns
int the length of the array
Throws
IllegalArgumentException if the object argument is not an array

getLong

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

long返回指定数组对象中索引组件的值。

Parameters
array Object: the array
index int: the index
Returns
long the value of the indexed component in the specified array
Throws
NullPointerException If the specified object is null
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

也可以看看:

getShort

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

返回指定数组对象中索引组件的值,如 short

Parameters
array Object: the array
index int: the index
Returns
short the value of the indexed component in the specified array
Throws
NullPointerException If the specified object is null
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

也可以看看:

newInstance

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

用指定的组件类型和长度创建一个新数组。 调用这个方法等同于创建一个数组,如下所示:

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

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
Throws
NullPointerException if the specified componentType parameter is null
IllegalArgumentException if componentType is TYPE
NegativeArraySizeException if the specified length is negative

newInstance

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

用指定的组件类型和尺寸创建一个新数组。 如果componentType表示非阵列类或接口,新阵列具有dimensions.length尺寸和componentType作为其成分的类型。 如果componentType表示一个数组类,则新数组的维数等于总和dimensions.length和维数componentType 在这种情况下,新阵列的组件类型是组件类型componentType

新数组的维数不得超过实现支持的数组维数(通常为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
Throws
NullPointerException if the specified componentType argument is null
IllegalArgumentException if the specified dimensions argument is a zero-dimensional array, or if the number of requested dimensions exceeds the limit on the number of array dimensions supported by the implementation (typically 255), or if componentType is TYPE.
NegativeArraySizeException if any of the components in the specified dimensions argument is negative.

set

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

将指定数组对象的索引组件的值设置为指定的新值。 如果数组具有原始组件类型,则新值将自动解包。

Parameters
array Object: the array
index int: the index into the array
value Object: the new value of the indexed component
Throws
NullPointerException If the specified object argument is null
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

setBoolean

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

将指定数组对象的索引组件的值设置为指定的 boolean值。

Parameters
array Object: the array
index int: the index into the array
value boolean: the new value of the indexed component
Throws
NullPointerException If the specified object argument is null
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

也可以看看:

setByte

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

将指定数组对象的索引组件的值设置为指定的 byte值。

Parameters
array Object: the array
index int: the index into the array
value byte: the new value of the indexed component
Throws
NullPointerException If the specified object argument is null
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

也可以看看:

setChar

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

将指定数组对象的索引组件的值设置为指定的 char值。

Parameters
array Object: the array
index int: the index into the array
value char: the new value of the indexed component
Throws
NullPointerException If the specified object argument is null
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

也可以看看:

setDouble

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

将指定数组对象的索引组件的值设置为指定的 double值。

Parameters
array Object: the array
index int: the index into the array
value double: the new value of the indexed component
Throws
NullPointerException If the specified object argument is null
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

也可以看看:

setFloat

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

将指定数组对象的索引组件的值设置为指定的 float值。

Parameters
array Object: the array
index int: the index into the array
value float: the new value of the indexed component
Throws
NullPointerException If the specified object argument is null
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

也可以看看:

setInt

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

将指定数组对象的索引组件的值设置为指定的 int值。

Parameters
array Object: the array
index int: the index into the array
value int: the new value of the indexed component
Throws
NullPointerException If the specified object argument is null
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

也可以看看:

setLong

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

将指定数组对象的索引组件的值设置为指定的 long值。

Parameters
array Object: the array
index int: the index into the array
value long: the new value of the indexed component
Throws
NullPointerException If the specified object argument is null
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

也可以看看:

setShort

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

将指定数组对象的索引组件的值设置为指定的 short值。

Parameters
array Object: the array
index int: the index into the array
value short: the new value of the indexed component
Throws
NullPointerException If the specified object argument is null
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

也可以看看:

Hooray!