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 - 如果componentType为
Void.TYPE,或者请求的数组实例的维数超过255。
NegativeArraySizeException - 如果指定的
length为负数
public static Object newInstance(类<?> componentType, int... dimensions) throws IllegalArgumentException, NegativeArraySizeException
componentType表示非数组类或接口,则新数组具有dimensions.length尺寸和componentType作为其组件类型。
如果componentType表示数组类,则新数组的维数等于dimensions.length和dimensions.length数componentType之componentType 。
在这种情况下,新阵列的组件类型为componentType的组件类型。
新数组的维数不能超过255。
componentType - 表示新数组的组件类型的
类对象
dimensions - 表示新数组的
int的数组
int
NullPointerException - 如果指定的
componentType参数为空
IllegalArgumentException - 如果指定的
dimensions参数是零维数组,如果componentType为
Void.TYPE ,或者所请求的数组实例的维数超过255。
NegativeArraySizeException - 如果指定的
dimensions参数中的任何
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 - 如果指定的对象参数为空
IllegalArgumentException - 如果指定的对象参数不是数组,或者数组组件类型是原始的,并且解包转换失败
ArrayIndexOutOfBoundsException - 如果指定的
index参数为负数,或者如果大于或等于指定数组的长度
public static void setBoolean(Object array, int index, boolean z) throws IllegalArgumentException, ArrayIndexOutOfBoundsException
boolean值。
array - 数组
index - 数组中的索引
z - 索引组件的新值
NullPointerException - 如果指定的对象参数为空
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 - 如果指定的对象参数为空
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 - 如果指定的对象参数为空
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 - 如果指定的对象参数为空
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 - 如果指定的对象参数为空
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 - 如果指定的对象参数为空
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 - 如果指定的对象参数为空
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 - 如果指定的对象参数为空
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.