类 java.lang.reflect.Array
java.lang.Object
|
+----java.lang.reflect.Array
- public final class Array
- extends Object
Array 类提供动态创建和访问 Java 数组的静态方法。
获取或设置操作期间允许发生 Array 扩展转换,但若发生缩减转换则抛出 IllegalArgumentException 。
方法索引
- get(Object, int)
- 返回指定数组对象的下标部件值。
- getBoolean(Object, int)
- 以 boolean 类型返回指定数组对象的下标部件值
- getByte(Object, int)
- 以 byte 类型返回指定数组对象下标部件值 。
- getChar(Object, int)
- 以 char 类型返回指定数组对象下标部件值 。
- getDouble(Object, int)
- 以 double 类型返回指定数组对象下标部件值 。
- getFloat(Object, int)
- 以 float 类型返回指定数组对象下标部件值 。
- getInt(Object, int)
- 以 int 类型返回指定数组对象下标部件值 。
- getLength(Object)
- 以 int 类型返回指定数组对象的长度。
- getLong(Object, int)
- 以 long 类型返回指定数组对象下标部件值 。
- getShort(Object, int)
- 以 short 类型返回指定数组对象下标部件值 。
- newInstance(Class, int)
- 创建带有指定部件类型和长度的新数组。
- newInstance(Class, int[])
- 创建带有指定部件类型和尺寸的新数组。
- set(Object, int, Object)
- 将指定数组对象的下标部件值设置为指定新值。
- setBoolean(Object, int, boolean)
- 将指定数组对象的下标部件值设置为指定的 boolean 值。
- setByte(Object, int, byte)
- 将指定数组对象的下标部件值设置为指定的 boolean 值。
- setChar(Object, int, char)
- 将指定数组对象的下标部件值设置为指定的 byte 值。
- setDouble(Object, int, double)
- 将指定数组对象的下标部件值设置为指定的 double 值。
- setFloat(Object, int, float)
- 将指定数组对象的下标部件值设置为指定的 float 值。
- setInt(Object, int, int)
- 将指定数组对象的下标部件值设置为指定的 int 值。
- setLong(Object, int, long)
- 将指定数组对象的下标部件值设置为指定的 long 值。
- setShort(Object, int, short)
- 将指定数组对象的下标部件值设置为指定的 short 值。
方法
newInstance
public static Object newInstance(Class componentType,
int length) throws NegativeArraySizeException
- 创建有指定部件类型和长度的新数组。其效果是等价的数组创建表达式:
new componentType[length]
- 参数:
- componentType - 用于表示新数组部件类型的 Class 对象。
- length - 新数组的长度
- 返回值:
- 新数组
- 抛出:
NullPointerException
- 若指定的 componentType 参数为 null
- 抛出:
NegativeArraySizeException
- 若指定长度为负
newInstance
public static Object newInstance(Class componentType,
int dimensions[]) throws IllegalArgumentException, NegativeArraySizeException
- 创建有指定部件类型和尺寸的新数组。
其效果是等价的数组创建表达式:
new componentType[dimensions[0]][dimensions[1]]...
- 参数:
- componentType - 用于表示新数组部件类型的 Class 对象。
- dimensions - 用于表示新数组尺寸的 int 数组
- 返回值:
- 新数组
- 抛出:
NullPointerException
- 若指定 componentType 参数为 null
- 抛出:
IllegalArgumentException
- 若指定尺寸参数是零维数组或请求尺寸数超过了实现所支持的数组尺寸数的限制 (典型的是 255) 。
- 抛出:
NegativeArraySizeException
- 若指定尺寸参数中的任何部件为负。
getLength
public static native int getLength(Object array) throws IllegalArgumentException
- 以 int 类型返回指定数组对象的长度。
- 参数:
- array - 数组
- 返回值:
- 数组长度
- 抛出:
IllegalArgumentException
- 若对象参数不是数组
get
public static native Object get(Object array,
int index) throws IllegalArgumentException, ArrayIndexOutOfBoundsException
- 返回指定数组对象的下标部件值。若该值有一个原始类型,则自动将其打包在某对象里。
- 参数:
- array - 数组
- index - 下标
- 返回值:
- 指定数组的 (可能是打包的) 下标部件值
- 抛出:
NullPointerException
- 若指定对象为 null
- 抛出:
IllegalArgumentException
- 若指定对象不是数组
- 抛出:
ArrayIndexOutOfBoundsException
- 若指定下标参数为负或其大于或等于指定数组的长度
getBoolean
public static native boolean getBoolean(Object array,
int index) throws IllegalArgumentException, ArrayIndexOutOfBoundsException
- 以 boolean 类型返回指定数组对象的下标部件值。
- 参数:
- array - 数组
- index - 下标
- 返回值:
- 指定数组的下标部件值。
- 抛出:
NullPointerException
- 若指定对象为 null
- 抛出:
IllegalArgumentException
- 若指定对象不是数组或不能将下标元素转换为标志或扩展的返回类型
- 抛出:
ArrayIndexOutOfBoundsException
- 若指定下标参数为负或其大于或等于指定数组的长度
- 参见:
- get
getByte
public static native byte getByte(Object array,
int index) throws IllegalArgumentException, ArrayIndexOutOfBoundsException
- 以 byte 类型返回指定数组对象下标部件值。
- 参数:
- array - 数组
- index - 下标
- 返回值:
- 指定数组下标部件值。
- 抛出:
NullPointerException
- 若指定对象为 null
- 抛出:
IllegalArgumentException
- 若指定对象不是数组,或者下标元素不能被标志或扩展转换转换为返回类型
- 抛出:
ArrayIndexOutOfBoundsException
- 若指定下标参数为负或其大于或等于指定数组的长度
- 参见:
- get
getChar
public static native char getChar(Object array,
int index) throws IllegalArgumentException, ArrayIndexOutOfBoundsException
- 以 char 类型返回指定数组对象下标部件值 。
- 参数:
- array - 数组
- index - 下标
- 返回值:
- 指定数组下标部件值。
- 抛出:
NullPointerException
- 若指定对象为 null
- 抛出:
IllegalArgumentException
- 若指定对象不是数组,或下标元素不能被标志或扩展转换转换成返回类型
- 抛出:
ArrayIndexOutOfBoundsException
- 若指定下标参数为负或其大于等于或指定数组的长度
- 参见:
- get
getShort
public static native short getShort(Object array,
int index) throws IllegalArgumentException, ArrayIndexOutOfBoundsException
- 以 short 类型返回指定数组对象下标部件值 。
- 参数:
- array - 数组
- index - 下标
- 返回值:
- 指定数组下标部件值。
- 抛出:
NullPointerException
- 若指定对象为 null
- 抛出:
IllegalArgumentException
- 若指定对象不是数组,或下标元素不能被标志或扩展转换转换成返回类型
- 抛出:
ArrayIndexOutOfBoundsException
- 若指定下标参数为负或其大于或等于指定数组的长度
- 参见:
- get
getInt
public static native int getInt(Object array,
int index) throws IllegalArgumentException, ArrayIndexOutOfBoundsException
- 以 int 类型返回指定数组对象下标部件值 。
- 参数:
- array - 数组
- index - 下标
- 返回值:
- 指定数组下标部件值。
- 抛出:
NullPointerException
- 若指定对象为 null
- 抛出:
IllegalArgumentException
- 若指定对象不是数组,或下标元素不能被标志或扩展转换转换成返回类型
- 抛出:
ArrayIndexOutOfBoundsException
- 若指定下标参数为负或其大于等于指定数组的长度
- 参见:
- get
getLong
public static native long getLong(Object array,
int index) throws IllegalArgumentException, ArrayIndexOutOfBoundsException
- 以 long 类型返回指定数组对象下标部件值 。
- 参数:
- array - 数组
- index - 下标
- 返回值:
- 指定数组的下标部件值。
- 抛出:
NullPointerException
- 若指定对象为 null
- 抛出:
IllegalArgumentException
- 若指定对象不是数组,或下标元素不能被标志或扩展转换转换成返回类型
- 抛出:
ArrayIndexOutOfBoundsException
- 若指定下标参数为负或其大于等于指定数组的长度
- 参见:
- get
getFloat
public static native float getFloat(Object array,
int index) throws IllegalArgumentException, ArrayIndexOutOfBoundsException
- 以 float 类型返回指定数组对象下标部件值 。
- 参数:
- array - 数组
- index - 下标
- 返回值:
- 指定数组下标部件值。
- 抛出:
NullPointerException
- 若指定对象为 null
- 抛出:
IllegalArgumentException
- 若指定对象不是数组,或下标元素不能被标志或扩展转换转换成返回类型
- 抛出:
ArrayIndexOutOfBoundsException
- 若指定下标参数为负或其大于等于指定数组的长度
- 参见:
- get
getDouble
public static native double getDouble(Object array,
int index) throws IllegalArgumentException, ArrayIndexOutOfBoundsException
- 以 double 类型返回指定数组对象下标部件值 。
- 参数:
- array - 数组
- index - 下标
- 返回值:
- 指定数组下标部件值。
- 抛出:
NullPointerException
- 若指定对象为 null
- 抛出:
IllegalArgumentException
- 若指定对象不是数组,或下标元素不能被标志或扩展转换转换成返回类型
- 抛出:
ArrayIndexOutOfBoundsException
- 若指定下标参数为负或其大于或等于指定数组的长度
- 参见:
- get
set
public static native void set(Object array,
int index,
Object value) throws IllegalArgumentException, ArrayIndexOutOfBoundsException
- 将指定数组对象的下标部件值设置为指定新值。若数组有原始部件类型,则首先将新值自动解包。
- 参数:
- array - 数组
- index - 数组所加的下标
- value - 下标部件的新值。
- 抛出:
NullPointerException
- 若指定对象参数为 null ,或数组部件类型是原始类型且指定值为 null
- 抛出:
IllegalArgumentException
- 若指定对象参数不是数组,或若数组部件类型是原始类型且指定值不能被未解包和标志或未解包和扩展转换的组合转换成原始类型
- 抛出:
ArrayIndexOutOfBoundsException
- 若指定下标参数为负或其大于或等于指定数组的长度
setBoolean
public static native void setBoolean(Object array,
int index,
boolean z) throws IllegalArgumentException, ArrayIndexOutOfBoundsException
- 将指定数组对象的下标部件值设置为指定的 boolean 值。
- 参数:
- array - 数组
- index - 数组所加的下标
- value - 下标部件的新值。
- 抛出:
NullPointerException
- 若指定对象参数为 null
- 抛出:
IllegalArgumentException
- 若指定对象参数不是数组,或指定值不能被标志或原始扩展转换转换成基本数组的部件类型
- 抛出:
ArrayIndexOutOfBoundsException
- 若指定下标参数为负或其大于或等于指定数组的长度
- 参见:
- set
setByte
public static native void setByte(Object array,
int index,
byte b) throws IllegalArgumentException, ArrayIndexOutOfBoundsException
- 将指定数组对象的下标部件值设置为指定的 boolean 值。
- 参数:
- array - 数组
- index - 数组所加的下标
- value - 下标部件的新值。
- 抛出:
NullPointerException
- 若指定对象参数为 null
- 抛出:
IllegalArgumentException
- 若指定对象参数不是数组,或下标元素不能被标志或原始扩展转换转换成基本数组的部件类型
- 抛出:
ArrayIndexOutOfBoundsException
- 若指定下标参数为负或其大于或等于指定数组的长度
- 参见:
- set
setChar
public static native void setChar(Object array,
int index,
char c) throws IllegalArgumentException, ArrayIndexOutOfBoundsException
- 将指定数组对象下标部件值设置为指定 byte 值。
- 参数:
- array - 数组
- index - 数组所加的下标
- value - 下标部件的新值。
- 抛出:
NullPointerException
- 若指定对象参数为 null
- 抛出:
IllegalArgumentException
- 若指定对象参数不是数组,或指定值不能被标志或原始扩展转换转换成基本数组的部件类型
- 抛出:
ArrayIndexOutOfBoundsException
- 若指定下标参数为负或其大于或等于指定数组的长度
- 参见:
- set
setShort
public static native void setShort(Object array,
int index,
short s) throws IllegalArgumentException, ArrayIndexOutOfBoundsException
- 将指定数组对象的下标部件值设置为指定的 short 值。
- 参数:
- array - 数组
- index - 数组所加的下标
- value - 下标部件的新值。
- 抛出:
NullPointerException
- 若指定对象参数为 null
- 抛出:
IllegalArgumentException
- 若指定对象参数不是数组,或指定值不能被标志或原始扩展转换转换成基本数组的部件类型
- 抛出:
ArrayIndexOutOfBoundsException
- 若指定下标参数为负或其大于或等于指定数组长度
- 参见:
- set
setInt
public static native void setInt(Object array,
int index,
int i) throws IllegalArgumentException, ArrayIndexOutOfBoundsException
- 将指定数组对象下标部件值设置为指定 int 值。
- 参数:
- array - 数组
- index - 数组所加的下标
- value - 下标部件的新值。
- 抛出:
NullPointerException
- 若指定对象参数为 null
- 抛出:
IllegalArgumentException
- 若指定对象参数不是数组,或将指定值不能被标志或原始扩展转换转换成基本数组的部件类型
- 抛出:
ArrayIndexOutOfBoundsException
- 若指定下标参数为负或其大于或等于指定数组长度
- 参见:
- set
setLong
public static native void setLong(Object array,
int index,
long l) throws IllegalArgumentException, ArrayIndexOutOfBoundsException
- 将指定数组对象的下标部件值设置为指定的 long 值。
- 参数:
- array - 数组
- index - 数组所加的下标
- value - 下标部件的新值。
- 抛出:
NullPointerException
- 若指定对象参数为 null
- 抛出:
IllegalArgumentException
- 若指定对象参数不是数组,或指定值不能被标志或原始扩展转换转换成基本数组的部件类型
- 抛出:
ArrayIndexOutOfBoundsException
- 若指定下标参数为负或其大于或等于指定数组的长度
- 参见:
- set
setFloat
public static native void setFloat(Object array,
int index,
float f) throws IllegalArgumentException, ArrayIndexOutOfBoundsException
- 将指定数组对象的下标部件值设置为指定的 float 值。
- 参数:
- array - 数组
- index - 数组所加的下标
- value - 下标部件的新值。
- 抛出:
NullPointerException
- 若指定对象参数为 null
- 抛出:
IllegalArgumentException
- 若指定对象参数不是数组,或指定值不能被标志或原始扩展转换转换成基本数组的部件类型
- 抛出:
ArrayIndexOutOfBoundsException
- 若指定下标参数为负或其大于或等于指定数组的长度
- 参见:
- set
setDouble
public static native void setDouble(Object array,
int index,
double d) throws IllegalArgumentException, ArrayIndexOutOfBoundsException
- 将指定数组对象的下标部件值设置为指定的 double 值。
- 参数:
- array - 数组
- index - 数组所加的下标
- value - 下标部件的新值。
- 抛出:
NullPointerException
- 若指定对象参数为 null
- 抛出:
IllegalArgumentException
- 若指定对象参数不是数组,或指定值不能被标志或原始扩展转换转换成基本数组的部件类型
- 抛出:
ArrayIndexOutOfBoundsException
- 若指定下标参数为负或其大于或等于指定数组的长度
- 参见:
- set