public final class Array extends Object
Array
类提供了动态创建和访问java数组的静态方法。
Array
允许扩大转换在获取或设置操作发生,但抛出IllegalArgumentException
如果缩小转换会发生。
Modifier and Type | Method and Description |
---|---|
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 。
|
static long |
getLong(Object array, int index)
返回指定数组中的索引组件对象的值,作为一个
long 。
|
static short |
getShort(Object array, int index)
返回指定数组中的索引组件对象的值,作为一个
short 。
|
static Object |
newInstance(类<?> componentType, int... dimensions)
用指定的组件类型和尺寸创建一个新的数组。
|
static Object |
newInstance(类<?> componentType, int length)
用指定的组件类型和长度创建一个新的数组。
|
static void |
set(Object array, int index, Object value)
将指定数组对象的索引组件的值设置为指定的新值。
|
static void |
setBoolean(Object array, int index, boolean z)
设置指定的
boolean 值的索引组件指定数组的对象的值。
|
static void |
setByte(Object array, int index, byte b)
设置指定的
byte 值的索引组件指定数组的对象的值。
|
static void |
setChar(Object array, int index, char c)
设置指定的
char 值的索引组件指定数组的对象的值。
|
static void |
setDouble(Object array, int index, double d)
设置指定的
double 值的索引组件指定数组的对象的值。
|
static void |
setFloat(Object array, int index, float f)
设置指定的
float 值的索引组件指定数组的对象的值。
|
static void |
setInt(Object array, int index, int i)
设置指定的
int 值的索引组件指定数组的对象的值。
|
static void |
setLong(Object array, int index, long l)
设置指定的
long 值的索引组件指定数组的对象的值。
|
static void |
setShort(Object array, int index, short s)
设置指定的
short 值的索引组件指定数组的对象的值。
|
public static Object newInstance(类<?> componentType, int length) throws NegativeArraySizeException
int[] x = {length}; Array.newInstance(componentType, x);
新数组的维数数不得超过255。
componentType
代表新数组的组件类型的
类
对象
length
-新数组的长度
NullPointerException
-如果指定
componentType
参数为空
IllegalArgumentException
如果成分类型是
Void.TYPE
或者所要求的阵列实例的维数超过255。
NegativeArraySizeException
-如果指定
length
是负的
public static Object newInstance(类<?> componentType, int... dimensions) throws IllegalArgumentException, NegativeArraySizeException
componentType
代表非数组的类或接口,新的阵列具有
dimensions.length
尺寸和
componentType
其组件类型。如果
componentType
表示数组类,对新的数组的维数等于
dimensions.length
和尺寸
componentType
数量总和。在这种情况下,新数组的组件类型是
componentType
组件类型。
新数组的维数数不得超过255。
componentType
代表新数组的组件类型的
类
对象
dimensions
-
int
代表新数组的维数的数组
NullPointerException
-如果指定
componentType
参数为null
IllegalArgumentException
-如果指定
dimensions
参数是一零维的数组,如果是
Void.TYPE
成分类型,或者如果要求尺寸的数组实例数超过255。
NegativeArraySizeException
-如果在指定的
dimensions
参数的分量为负。
public static int getLength(Object array) throws IllegalArgumentException
int
。
array
-阵列
IllegalArgumentException
-如果对象参数不是数组
public static Object get(Object array, int index) throws IllegalArgumentException, ArrayIndexOutOfBoundsException
array
-阵列
index
-指数
NullPointerException
-指定对象是否为空
IllegalArgumentException
-如果指定的对象不是数组
ArrayIndexOutOfBoundsException
-如果指定
index
参数为负,或如果它大于或等于指定数组的长度
public static boolean getBoolean(Object array, int index) throws IllegalArgumentException, ArrayIndexOutOfBoundsException
boolean
。
array
-阵列
index
-指数
NullPointerException
-指定对象是否为空
IllegalArgumentException
-如果指定的对象不是一个数组,或如果索引元素不能被转换为返回类型的身份或扩大转换
ArrayIndexOutOfBoundsException
-如果指定
index
参数为负,或如果它大于或等于指定数组的长度
get(java.lang.Object, int)
public static byte getByte(Object array, int index) throws IllegalArgumentException, ArrayIndexOutOfBoundsException
byte
。
array
-阵列
index
-指数
NullPointerException
-指定对象是否为空
IllegalArgumentException
-如果指定的对象不是一个数组,或如果索引元素不能被转换为返回类型的身份或扩大转换
ArrayIndexOutOfBoundsException
-如果指定
index
参数为负,或如果它大于或等于指定数组的长度
get(java.lang.Object, int)
public static char getChar(Object array, int index) throws IllegalArgumentException, ArrayIndexOutOfBoundsException
char
。
array
-阵列
index
-指数
NullPointerException
-指定对象是否为空
IllegalArgumentException
-如果指定的对象不是一个数组,或如果索引元素不能被转换为返回类型的身份或扩大转换
ArrayIndexOutOfBoundsException
-如果指定
index
参数为负,或如果它大于或等于指定数组的长度
get(java.lang.Object, int)
public static short getShort(Object array, int index) throws IllegalArgumentException, ArrayIndexOutOfBoundsException
short
。
array
-阵列
index
-指数
NullPointerException
-指定对象是否为空
IllegalArgumentException
-如果指定的对象不是一个数组,或如果索引元素不能被转换为返回类型的身份或扩大转换
ArrayIndexOutOfBoundsException
-如果指定
index
参数为负,或如果它大于或等于指定数组的长度
get(java.lang.Object, int)
public static int getInt(Object array, int index) throws IllegalArgumentException, ArrayIndexOutOfBoundsException
int
。
array
-阵列
index
-指数
NullPointerException
-指定对象是否为空
IllegalArgumentException
-如果指定的对象不是一个数组,或如果索引元素不能被转换为返回类型的身份或扩大转换
ArrayIndexOutOfBoundsException
-如果指定
index
参数为负,或如果它大于或等于指定数组的长度
get(java.lang.Object, int)
public static long getLong(Object array, int index) throws IllegalArgumentException, ArrayIndexOutOfBoundsException
long
。
array
-阵列
index
-指数
NullPointerException
-指定对象是否为空
IllegalArgumentException
-如果指定的对象不是一个数组,或如果索引元素不能被转换为返回类型的身份或扩大转换
ArrayIndexOutOfBoundsException
-如果指定
index
参数为负,或如果它大于或等于指定数组的长度
get(java.lang.Object, int)
public static float getFloat(Object array, int index) throws IllegalArgumentException, ArrayIndexOutOfBoundsException
float
。
array
-阵列
index
-指数
NullPointerException
-指定对象是否为空
IllegalArgumentException
-如果指定的对象不是一个数组,或如果索引元素不能被转换为返回类型的身份或扩大转换
ArrayIndexOutOfBoundsException
-如果指定
index
参数为负,或如果它大于或等于指定数组的长度
get(java.lang.Object, int)
public static double getDouble(Object array, int index) throws IllegalArgumentException, ArrayIndexOutOfBoundsException
double
。
array
-阵列
index
-指数
NullPointerException
-指定对象是否为空
IllegalArgumentException
-如果指定的对象不是一个数组,或如果索引元素不能被转换为返回类型的身份或扩大转换
ArrayIndexOutOfBoundsException
-如果指定
index
参数为负,或如果它大于或等于指定数组的长度
get(java.lang.Object, int)
public static void set(Object array, int index, Object value) throws IllegalArgumentException, ArrayIndexOutOfBoundsException
array
-阵列
index
-索引数组
value
-索引组件的新价值
NullPointerException
-如果指定对象参数为null
IllegalArgumentException
-如果指定对象参数不是数组,或如果数组的组件类型是原始和解包转换失败
ArrayIndexOutOfBoundsException
-如果指定
index
参数为负,或如果它大于或等于指定数组的长度
public static void setBoolean(Object array, int index, boolean z) throws IllegalArgumentException, ArrayIndexOutOfBoundsException
boolean
值的索引组件指定数组的对象的值。
array
-阵列
index
-索引数组
z
-索引组件的新价值
NullPointerException
-如果指定对象参数为null
IllegalArgumentException
-如果指定对象参数不是数组,或者如果指定值不能转换为身份或者原始的扩大转换基本数组的组件类型
ArrayIndexOutOfBoundsException
-如果指定
index
参数为负,或如果它大于或等于指定数组的长度
set(java.lang.Object, int, java.lang.Object)
public static void setByte(Object array, int index, byte b) throws IllegalArgumentException, ArrayIndexOutOfBoundsException
byte
值的索引组件指定数组的对象的值。
array
-阵列
index
-索引数组
b
-索引组件的新价值
NullPointerException
-如果指定对象参数为null
IllegalArgumentException
-如果指定对象参数不是数组,或者如果指定值不能转换为身份或者原始的扩大转换基本数组的组件类型
ArrayIndexOutOfBoundsException
-如果指定
index
参数为负,或如果它大于或等于指定数组的长度
set(java.lang.Object, int, java.lang.Object)
public static void setChar(Object array, int index, char c) throws IllegalArgumentException, ArrayIndexOutOfBoundsException
char
值的索引组件指定数组的对象的值。
array
-阵列
index
-索引数组
c
-索引组件的新价值
NullPointerException
-如果指定对象参数为null
IllegalArgumentException
-如果指定对象参数不是数组,或者如果指定值不能转换为身份或者原始的扩大转换基本数组的组件类型
ArrayIndexOutOfBoundsException
-如果指定
index
参数为负,或如果它大于或等于指定数组的长度
set(java.lang.Object, int, java.lang.Object)
public static void setShort(Object array, int index, short s) throws IllegalArgumentException, ArrayIndexOutOfBoundsException
short
值的索引组件指定数组的对象的值。
array
-阵列
index
-索引数组
s
-索引组件的新价值
NullPointerException
-如果指定对象参数为null
IllegalArgumentException
-如果指定对象参数不是数组,或者如果指定值不能转换为身份或者原始的扩大转换基本数组的组件类型
ArrayIndexOutOfBoundsException
-如果指定
index
参数为负,或如果它大于或等于指定数组的长度
set(java.lang.Object, int, java.lang.Object)
public static void setInt(Object array, int index, int i) throws IllegalArgumentException, ArrayIndexOutOfBoundsException
int
值的索引组件指定数组的对象的值。
array
-阵列
index
-索引数组
i
-索引组件的新价值
NullPointerException
-如果指定对象参数为null
IllegalArgumentException
-如果指定对象参数不是数组,或者如果指定值不能转换为身份或者原始的扩大转换基本数组的组件类型
ArrayIndexOutOfBoundsException
-如果指定
index
参数为负,或如果它大于或等于指定数组的长度
set(java.lang.Object, int, java.lang.Object)
public static void setLong(Object array, int index, long l) throws IllegalArgumentException, ArrayIndexOutOfBoundsException
long
值的索引组件指定数组的对象的值。
array
-阵列
index
-索引数组
l
-索引组件的新价值
NullPointerException
-如果指定对象参数为null
IllegalArgumentException
-如果指定对象参数不是数组,或者如果指定值不能转换为身份或者原始的扩大转换基本数组的组件类型
ArrayIndexOutOfBoundsException
-如果指定
index
参数为负,或如果它大于或等于指定数组的长度
set(java.lang.Object, int, java.lang.Object)
public static void setFloat(Object array, int index, float f) throws IllegalArgumentException, ArrayIndexOutOfBoundsException
float
值的索引组件指定数组的对象的值。
array
-阵列
index
-索引数组
f
-索引组件的新价值
NullPointerException
-如果指定对象参数为null
IllegalArgumentException
-如果指定对象参数不是数组,或者如果指定值不能转换为身份或者原始的扩大转换基本数组的组件类型
ArrayIndexOutOfBoundsException
-如果指定
index
参数为负,或如果它大于或等于指定数组的长度
set(java.lang.Object, int, java.lang.Object)
public static void setDouble(Object array, int index, double d) throws IllegalArgumentException, ArrayIndexOutOfBoundsException
double
值的索引组件指定数组的对象的值。
array
-阵列
index
-索引数组
d
-索引组件的新价值
NullPointerException
-如果指定对象参数为null
IllegalArgumentException
-如果指定对象参数不是数组,或者如果指定值不能转换为身份或者原始的扩大转换基本数组的组件类型
ArrayIndexOutOfBoundsException
-如果指定
index
参数为负,或如果它大于或等于指定数组的长度
set(java.lang.Object, int, java.lang.Object)
Submit a bug or feature
For further API reference and developer documentation, see Java SE Documentation. That documentation contains more detailed, developer-targeted descriptions, with conceptual overviews, definitions of terms, workarounds, and working code examples.
Copyright © 1993, 2014, Oracle and/or its affiliates. All rights reserved.