在 Java 中,java.lang.Array
类包含了用于操作数组的静态方法。以下是 Array
类中所有的方法解析:
-
public static Object get(Object array, int index)
: 获取指定数组索引处的元素值。 -
public static boolean getBoolean(Object array, int index)
: 获取指定布尔型数组索引处的元素值。 -
public static byte getByte(Object array, int index)
: 获取指定字节型数组索引处的元素值。 -
public static char getChar(Object array, int index)
: 获取指定字符型数组索引处的元素值。 -
public static short getShort(Object array, int index)
: 获取指定短整型数组索引处的元素值。 -
public static int getInt(Object array, int index)
: 获取指定整型数组索引处的元素值。 -
public static long getLong(Object array, int index)
: 获取指定长整型数组索引处的元素值。 -
public static float getFloat(Object array, int index)
: 获取指定单精度浮点型数组索引处的元素值。 -
public static double getDouble(Object array, int index)
: 获取指定双精度浮点型数组索引处的元素值。 -
public static void set(Object array, int index, Object value)
: 设置指定数组索引处的元素值。 -
public static void setBoolean(Object array, int index, boolean value)
: 设置指定布尔型数组索引处的元素值。 -
public static void setByte(Object array, int index, byte value)
: 设置指定字节型数组索引处的元素值。 -
public static void setChar(Object array, int index, char value)
: 设置指定字符型数组索引处的元素值。 -
public static void setShort(Object array, int index, short value)
: 设置指定短整型数组索引处的元素值。 -
public static void setInt(Object array, int index, int value)
: 设置指定整型数组索引处的元素值。 -
public static void setLong(Object array, int index, long value)
: 设置指定长整型数组索引处的元素值。 -
public static void setFloat(Object array, int index, float value)
: 设置指定单精度浮点型数组索引处的元素值。 -
public static void setDouble(Object array, int index, double value)
: 设置指定双精度浮点型数组索引处的元素值。 -
public static int getLength(Object array)
: 获取指定数组的长度。 -
public static Object newInstance(Class<?> componentType, int length)
: 创建一个具有指定类型和长度的新数组。 -
public static Object newInstance(Class<?> componentType, int... dimensions)
: 创建一个具有指定类型和维度的新数组。 -
public static void fill(Object[] a, Object val)
: 将整个数组或指定范围内的元素填充为指定值。 -
public static void fill(Object[] a, int fromIndex, int toIndex, Object val)
: 将数组指定范围内的元素填充为指定值。 -
public static void sort(Object[] a)
: 对数组进行排序。 -
public static void sort(Object[] a, int fromIndex, int toIndex)
: 对数组指定范围内的元素进行排序。 -
public static String toString(Object[] a)
: 以字符串形式返回数组内容。