一、Arrays类概述
- 此类包含用来操作数组(比如排序和搜索)的各种方法,是一个与数组相关的工具类,提供了大量的静态方法,用来实现数组常见的操作。此类还包含一个允许将数组作为列表来查看的静态工厂。
- 除非特别注明,否则如果指定数组引用为 null,则此类中的方法都会抛出 NullPointerException。
- 此类中所含方法的文档都包括对实现 的简短描述。应该将这些描述视为实现注意事项,而不应将它们视为规范 的一部分。实现者应该可以随意替代其他算法,只要遵循规范本身即可。(例如,sort(Object[]) 使用的算法不必是一个合并排序算法,但它必须是稳定的。)
- 此类是 Java Collections Framework 的成员。
- public static String toString(数组),将参数数组编程字符串(按照默认格式:[元素1,元素2,元素3 ... ...])
- public static void sort(数组):按照默认升序(从小到大)对数组的元素进行排序。字符串数组也可以进行排序,默认按照字母升序。如果是自定义类型的数组,那么若要使用sort方法,这个自定义的类需要有Comparable或者Comparator接口的支持。
二、方法摘要
static
| asList(T... a) 返回一个受指定数组支持的固定大小的列表。 | |
static int | binarySearch(byte[] a, byte key) 使用二分搜索法来搜索指定的 byte 型数组,以获得指定的值。 | |
static int | binarySearch(byte[] a, int fromIndex, int toIndex, byte key) 使用二分搜索法来搜索指定的 byte 型数组的范围,以获得指定的值。 | |
static int | binarySearch(char[] a, char key) 使用二分搜索法来搜索指定的 char 型数组,以获得指定的值。 | |
static int | binarySearch(char[] a, int fromIndex, int toIndex, char key) 使用二分搜索法来搜索指定的 char 型数组的范围,以获得指定的值。 | |
static int | binarySearch(double[] a, double key) 使用二分搜索法来搜索指定的 double 型数组,以获得指定的值。 | |
static int | binarySearch(double[] a, int fromIndex, int toIndex, double key) 使用二分搜索法来搜索指定的 double 型数组的范围,以获得指定的值。 | |
static int | binarySearch(float[] a, float key) 使用二分搜索法来搜索指定的 float 型数组,以获得指定的值。 | |
static int | binarySearch(float[] a, int fromIndex, int toIndex, float key) 使用二分搜索法来搜索指定的 float 型数组的范围,以获得指定的值。 | |
static int | binarySearch(int[] a, int key) 使用二分搜索法来搜索指定的 int 型数组,以获得指定的值。 | |
static int | binarySearch(int[] a, int fromIndex, int toIndex, int key) 使用二分搜索法来搜索指定的 int 型数组的范围,以获得指定的值。 | |
static int | binarySearch(long[] a, int fromIndex, int toIndex, long key) 使用二分搜索法来搜索指定的 long 型数组的范围,以获得指定的值。 | |
static int | binarySearch(long[] a, long key) 使用二分搜索法来搜索指定的 long 型数组,以获得指定的值。 | |
static int | binarySearch(Object[] a, int fromIndex, int toIndex, Object key) 使用二分搜索法来搜索指定数组的范围,以获得指定对象。 | |
static int | binarySearch(Object[] a, Object key) 使用二分搜索法来搜索指定数组,以获得指定对象。 | |
static int | binarySearch(short[] a, int fromIndex, int toIndex, short key) 使用二分搜索法来搜索指定的 short 型数组的范围,以获得指定的值。 | |
static int | binarySearch(short[] a, short key) 使用二分搜索法来搜索指定的 short 型数组,以获得指定的值。 | |
static
| binarySearch(T[] a, int fromIndex, int toIndex, T key, Comparator<? super T> c) 使用二分搜索法来搜索指定数组的范围,以获得指定对象。 | |
static
| binarySearch(T[] a, T key, Comparator<? super T> c) 使用二分搜索法来搜索指定数组,以获得指定对象。 | |
static boolean[] | copyOf(boolean[] original, int newLength) 复制指定的数组,截取或用 false 填充(如有必要),以使副本具有指定的长度。 | |
static byte[] | copyOf(byte[] original, int newLength) 复制指定的数组,截取或用 0 填充(如有必要),以使副本具有指定的长度。 | |
static char[] | copyOf(char[] original, int newLength) 复制指定的数组,截取或用 null 字符填充(如有必要),以使副本具有指定的长度。 | |
static double[] | copyOf(double[] original, int newLength) 复制指定的数组,截取或用 0 填充(如有必要),以使副本具有指定的长度。 | |
static float[] | copyOf(float[] original, int newLength) 复制指定的数组,截取或用 0 填充(如有必要),以使副本具有指定的长度。 | |
static int[] | copyOf(int[] original, int newLength) 复制指定的数组,截取或用 0 填充(如有必要),以使副本具有指定的长度。 | |
static long[] | copyOf(long[] original, int newLength) 复制指定的数组,截取或用 0 填充(如有必要),以使副本具有指定的长度。 | |
static short[] | copyOf(short[] original, int newLength) 复制指定的数组,截取或用 0 填充(如有必要),以使副本具有指定的长度。 | |
static
| copyOf(T[] original, int newLength) 复制指定的数组,截取或用 null 填充(如有必要),以使副本具有指定的长度。 | |
static
| copyOf(U[] original, int newLength, Class<? extends T[]> newType) 复制指定的数组,截取或用 null 填充(如有必要),以使副本具有指定的长度。 | |
static boolean[] | copyOfRange(boolean[] original, int from, int to) 将指定数组的指定范围复制到一个新数组。 | |
static byte[] | copyOfRange(byte[] original, int from, int to) 将指定数组的指定范围复制到一个新数组。 | |
static char[] | copyOfRange(char[] original, int from, int to) 将指定数组的指定范围复制到一个新数组。 | |
static double[] | copyOfRange(double[] original, int from, int to) 将指定数组的指定范围复制到一个新数组。 | |
static float[] | copyOfRange(float[] original, int from, int to) 将指定数组的指定范围复制到一个新数组。 | |
static int[] | copyOfRange(int[] original, int from, int to) 将指定数组的指定范围复制到一个新数组。 | |
static long[] | copyOfRange(long[] original, int from, int to) 将指定数组的指定范围复制到一个新数组。 | |
static short[] | copyOfRange(short[] original, int from, int to) 将指定数组的指定范围复制到一个新数组。 | |
static
| copyOfRange(T[] original, int from, int to) 将指定数组的指定范围复制到一个新数组。 | |
static
| copyOfRange(U[] original, int from, int to, Class<? extends T[]> newType) 将指定数组的指定范围复制到一个新数组。 | |
static boolean | deepEquals(Object[] a1, Object[] a2) 如果两个指定数组彼此是深层相等 的,则返回 true。 | |
static int | deepHashCode(Object[] a) 基于指定数组的“深层内容”返回哈希码。 | |
static String | deepToString(Object[] a) 返回指定数组“深层内容”的字符串表示形式。 | |
static boolean | equals(boolean[] a, boolean[] a2) 如果两个指定的 boolean 型数组彼此相等,则返回 true。 | |
static boolean | equals(byte[] a, byte[] a2) 如果两个指定的 byte 型数组彼此相等,则返回 true。 | |
static boolean | equals(char[] a, char[] a2) 如果两个指定的 char 型数组彼此相等,则返回 true。 | |
static boolean | equals(double[] a, double[] a2) 如果两个指定的 double 型数组彼此相等,则返回 true。 | |
static boolean | equals(float[] a, float[] a2) 如果两个指定的 float 型数组彼此相等,则返回 true。 | |
static boolean | equals(int[] a, int[] a2) 如果两个指定的 int 型数组彼此相等,则返回 true。 | |
static boolean | equals(long[] a, long[] a2) 如果两个指定的 long 型数组彼此相等,则返回 true。 | |
static boolean | equals(Object[] a, Object[] a2) 如果两个指定的 Objects 数组彼此相等,则返回 true。 | |
static boolean | equals(short[] a, short[] a2) 如果两个指定的 short 型数组彼此相等,则返回 true。 | |
static void | fill(boolean[] a, boolean val) 将指定的 boolean 值分配给指定 boolean 型数组的每个元素。 | |
static void | fill(boolean[] a, int fromIndex, int toIndex, boolean val) 将指定的 boolean 值分配给指定 boolean 型数组指定范围中的每个元素。 | |
static void | fill(byte[] a, byte val) 将指定的 byte 值分配给指定 byte 节型数组的每个元素。 | |
static void | fill(byte[] a, int fromIndex, int toIndex, byte val) 将指定的 byte 值分配给指定 byte 型数组指定范围中的每个元素。 | |
static void | fill(char[] a, char val) 将指定的 char 值分配给指定 char 型数组的每个元素。 | |
static void | fill(char[] a, int fromIndex, int toIndex, char val) 将指定的 char 值分配给指定 char 型数组指定范围中的每个元素。 | |
static void | fill(double[] a, double val) 将指定的 double 值分配给指定 double 型数组的每个元素。 | |
static void | fill(double[] a, int fromIndex, int toIndex, double val) 将指定的 double 值分配给指定 double 型数组指定范围中的每个元素。 | |
static void | fill(float[] a, float val) 将指定的 float 值分配给指定 float 型数组的每个元素。 | |
static void | fill(float[] a, int fromIndex, int toIndex, float val) 将指定的 float 值分配给指定 float 型数组指定范围中的每个元素。 | |
static void | fill(int[] a, int val) 将指定的 int 值分配给指定 int 型数组的每个元素。 | |
static void | fill(int[] a, int fromIndex, int toIndex, int val) 将指定的 int 值分配给指定 int 型数组指定范围中的每个元素。 | |
static void | fill(long[] a, int fromIndex, int toIndex, long val) 将指定的 long 值分配给指定 long 型数组指定范围中的每个元素。 | |
static void | fill(long[] a, long val) 将指定的 long 值分配给指定 long 型数组的每个元素。 | |
static void | fill(Object[] a, int fromIndex, int toIndex, Object val) 将指定的 Object 引用分配给指定 Object 数组指定范围中的每个元素。 | |
static void | fill(Object[] a, Object val) 将指定的 Object 引用分配给指定 Object 数组的每个元素。 | |
static void | fill(short[] a, int fromIndex, int toIndex, short val) 将指定的 short 值分配给指定 short 型数组指定范围中的每个元素。 | |
static void | fill(short[] a, short val) 将指定的 short 值分配给指定 short 型数组的每个元素。 | |
static int | hashCode(boolean[] a) 基于指定数组的内容返回哈希码。 | |
static int | hashCode(byte[] a) 基于指定数组的内容返回哈希码。 | |
static int | hashCode(char[] a) 基于指定数组的内容返回哈希码。 | |
static int | hashCode(double[] a) 基于指定数组的内容返回哈希码。 | |
static int | hashCode(float[] a) 基于指定数组的内容返回哈希码。 | |
static int | hashCode(int[] a) 基于指定数组的内容返回哈希码。 | |
static int | hashCode(long[] a) 基于指定数组的内容返回哈希码。 | |
static int | hashCode(Object[] a) 基于指定数组的内容返回哈希码。 | |
static int | hashCode(short[] a) 基于指定数组的内容返回哈希码。 | |
static void | sort(byte[] a) 对指定的 byte 型数组按数字升序进行排序。 | |
static void | sort(byte[] a, int fromIndex, int toIndex) 对指定 byte 型数组的指定范围按数字升序进行排序。 | |
static void | sort(char[] a) 对指定的 char 型数组按数字升序进行排序。 | |
static void | sort(char[] a, int fromIndex, int toIndex) 对指定 char 型数组的指定范围按数字升序进行排序。 | |
static void | sort(double[] a) 对指定的 double 型数组按数字升序进行排序。 | |
static void | sort(double[] a, int fromIndex, int toIndex) 对指定 double 型数组的指定范围按数字升序进行排序。 | |
static void | sort(float[] a) 对指定的 float 型数组按数字升序进行排序。 | |
static void | sort(float[] a, int fromIndex, int toIndex) 对指定 float 型数组的指定范围按数字升序进行排序。 | |
static void | sort(int[] a) 对指定的 int 型数组按数字升序进行排序。 | |
static void | sort(int[] a, int fromIndex, int toIndex) 对指定 int 型数组的指定范围按数字升序进行排序。 | |
static void | sort(long[] a) 对指定的 long 型数组按数字升序进行排序。 | |
static void | sort(long[] a, int fromIndex, int toIndex) 对指定 long 型数组的指定范围按数字升序进行排序。 | |
static void | sort(Object[] a) 根据元素的自然顺序对指定对象数组按升序进行排序。 | |
static void | sort(Object[] a, int fromIndex, int toIndex) 根据元素的自然顺序对指定对象数组的指定范围按升序进行排序。 | |
static void | sort(short[] a) 对指定的 short 型数组按数字升序进行排序。 | |
static void | sort(short[] a, int fromIndex, int toIndex) 对指定 short 型数组的指定范围按数字升序进行排序。 | |
static
| sort(T[] a, Comparator<? super T> c) 根据指定比较器产生的顺序对指定对象数组进行排序。 | |
static
| sort(T[] a, int fromIndex, int toIndex, Comparator<? super T> c) 根据指定比较器产生的顺序对指定对象数组的指定范围进行排序。 | |
static String | toString(boolean[] a) 返回指定数组内容的字符串表示形式。 | |
static String | toString(byte[] a) 返回指定数组内容的字符串表示形式。 | |
static String | toString(char[] a) 返回指定数组内容的字符串表示形式。 | |
static String | toString(double[] a) 返回指定数组内容的字符串表示形式。 | |
static String | toString(float[] a) 返回指定数组内容的字符串表示形式。 | |
static String | toString(int[] a) 返回指定数组内容的字符串表示形式。 | |
static String | toString(long[] a) 返回指定数组内容的字符串表示形式。 | |
static String | toString(Object[] a) 返回指定数组内容的字符串表示形式。 | |
static String | toString(short[] a) 返回指定数组内容的字符串表示形式。 |