|
JavaTM Platform Standard Ed. 6 |
|||||||||
| 上一个类 下一个类 | 框架 无框架 | |||||||||
| 摘要: 嵌套 | 字段 | 构造方法 | 方法 | 详细信息: 字段 | 构造方法 | 方法 | |||||||||
java.lang.Objectjava.lang.reflect.Array
public final class Array
Array 类提供了动态创建和访问 Java 数组的方法。
Array 允许在执行 get 或 set 操作期间进行扩展转换,但如果发生收缩转换,则抛出 IllegalArgumentException。
| 方法摘要 | |
|---|---|
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(Class<?> componentType,
int... dimensions)
创建一个具有指定的组件类型和维度的新数组。 |
static Object |
newInstance(Class<?> 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 值。 |
| 从类 java.lang.Object 继承的方法 |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| 方法详细信息 |
|---|
public static Object newInstance(Class<?> componentType,
int length)
throws NegativeArraySizeException
int[] x = {length};
Array.newInstance(componentType, x);
componentType - 表示新数组的组件类型的 Class 对象length - 新数组的长度
NullPointerException - 如果指定的 componentType 参数为 null
IllegalArgumentException - 如果 componentType 为 Void.TYPE
NegativeArraySizeException - 如果指定的 length 为负
public static Object newInstance(Class<?> componentType,
int... dimensions)
throws IllegalArgumentException,
NegativeArraySizeException
componentType 表示一个非数组类或接口,则新数组具有 dimensions.length 维度,并且将 componentType 作为其组件类型。如果 componentType 表示一个数组类,则新数组的维数等于 dimensions.length 和 componentType 的维数的总和。在这种情况下,新数组的组件类型为 componentType 的组件类型。
新数组的维数不能超过该实现所支持的数组维数(通常为 255)。
componentType - 表示新数组的组件类型的 Class 对象dimensions - 表示新数组维度的 int 数组
NullPointerException - 如果指定的 componentType 参数为 null
IllegalArgumentException - 如果指定的 dimensions 参数是一个零维度的数组,或者所请求的维数超过了该实现所支持的数组维数的限制(通常为 225),或者度的数组,或者所请求的维数超过了该实现所支持的数组维数的限制(通常为 225),或者 componentType 为 Void.TYPE。
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 - 如果指定对象为 null
IllegalArgumentException - 如果指定对象不是一个数组
ArrayIndexOutOfBoundsException - 如果指定的 index 参数为负,或者它大于等于指定数组的长度
public static boolean getBoolean(Object array,
int index)
throws IllegalArgumentException,
ArrayIndexOutOfBoundsException
boolean 形式返回指定数组对象中索引组件的值。
array - 数组index - 索引
NullPointerException - 如果指定对象为 null
IllegalArgumentException - 如果指定对象不是一个数组,或者无法通过一个恒等或扩展转换将索引元素转换为返回类型
ArrayIndexOutOfBoundsException - 如果指定的 index 参数为负,或者它大于等于指定数组的长度get(java.lang.Object, int)
public static byte getByte(Object array,
int index)
throws IllegalArgumentException,
ArrayIndexOutOfBoundsException
byte 形式返回指定数组对象中索引组件的值。
array - 数组index - 索引
NullPointerException - 如果指定对象为 null
IllegalArgumentException - 如果指定对象不是一个数组,或者无法通过一个恒等或扩展转换将索引元素转换为返回类型
ArrayIndexOutOfBoundsException - 如果指定的 index 参数为负,或者它大于等于指定数组的长度get(java.lang.Object, int)
public static char getChar(Object array,
int index)
throws IllegalArgumentException,
ArrayIndexOutOfBoundsException
char 形式返回指定数组对象中索引组件的值。
array - 数组index - 索引
NullPointerException - 如果指定对象为 null
IllegalArgumentException - 如果指定对象不是一个数组,或者无法通过一个恒等或扩展转换将索引元素转换为返回类型
ArrayIndexOutOfBoundsException - 如果指定的 index 参数为负,或者它大于等于指定数组的长度get(java.lang.Object, int)
public static short getShort(Object array,
int index)
throws IllegalArgumentException,
ArrayIndexOutOfBoundsException
short 形式返回指定数组对象中索引组件的值。
array - 数组index - 索引
NullPointerException - 如果指定对象为 null
IllegalArgumentException - 如果指定对象不是一个数组,或者无法通过一个恒等或扩展转换将索引元素转换为返回类型
ArrayIndexOutOfBoundsException - 如果指定的 index 参数为负,或者它大于等于指定数组的长度get(java.lang.Object, int)
public static int getInt(Object array,
int index)
throws IllegalArgumentException,
ArrayIndexOutOfBoundsException
int 形式返回指定数组对象中索引组件的值。
array - 数组index - 索引
NullPointerException - 如果指定对象为 null
IllegalArgumentException - 如果指定对象不是一个数组,或者无法通过一个恒等或扩展转换将索引元素转换为返回类型
ArrayIndexOutOfBoundsException - 如果指定的 index 参数为负,或者它大于等于指定数组的长度get(java.lang.Object, int)
public static long getLong(Object array,
int index)
throws IllegalArgumentException,
ArrayIndexOutOfBoundsException
long 形式返回指定数组对象中索引组件的值。
array - 数组index - 索引
NullPointerException - 如果指定对象为 null
IllegalArgumentException - 如果指定对象不是一个数组,或者无法通过一个恒等或扩展转换将索引元素转换为返回类型
ArrayIndexOutOfBoundsException - 如果指定的 index 参数为负,或者它大于等于指定数组的长度get(java.lang.Object, int)
public static float getFloat(Object array,
int index)
throws IllegalArgumentException,
ArrayIndexOutOfBoundsException
float 形式返回指定数组对象中索引组件的值。
array - 数组index - 索引
NullPointerException - 如果指定对象为 null
IllegalArgumentException - 如果指定对象不是一个数组,或者无法通过一个恒等或扩展转换将索引元素转换为返回类型
ArrayIndexOutOfBoundsException - 如果指定的 index 参数为负,或者它大于等于指定数组的长度get(java.lang.Object, int)
public static double getDouble(Object array,
int index)
throws IllegalArgumentException,
ArrayIndexOutOfBoundsException
double 形式返回指定数组对象中索引组件的值。
array - 数组index - 索引
NullPointerException - 如果指定对象为 null
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)
|
JavaTM Platform Standard Ed. 6 |
|||||||||
| 上一个类 下一个类 | 框架 无框架 | |||||||||
| 摘要: 嵌套 | 字段 | 构造方法 | 方法 | 详细信息: 字段 | 构造方法 | 方法 | |||||||||
版权所有 2007 Sun Microsystems, Inc. 保留所有权利。 请遵守许可证条款。另请参阅文档重新分发政策。