手册
目录
收藏772
分享
阅读791
更新时间2025-07-22
前言:
在本教程中,您将学习如何使用Java.util.Arrays类,简介java.util.Arrays类包含一个静态工厂,允许将数组视为列表。以下是关于数组的要点−该类包含各种操作数组的方法(例如排序和搜索)。
java.util.Arrays 类包含一个静态工厂,允许将数组视为列表。以下是关于数组的要点 −
该类包含各种操作数组的方法(例如排序和搜索)。
如果指定的数组引用为 null,则此类中的方法会抛出 NullPointerException。
以下是 java.util.Arrays 类的声明 −
| 序号 | 方法 & 描述 | 
|---|---|
| 1 | static  此方法返回由指定数组支持的固定大小的列表。  | 
| 2 | static int binarySearch(byte[] a, byte key)
 此方法使用二进制搜索算法在指定的字节数组中搜索指定的值。  | 
| 3 | static int binarySearch(byte[] a, int fromIndex, int toIndex, byte key)
 该方法使用二分查找算法在指定字节数组的范围内查找指定值。  | 
| 4 | static int binarySearch(char[] a, char key)
 此方法使用二进制搜索算法在指定的字符数组中搜索指定的值。  | 
| 5 | static int binarySearch(char[] a, int fromIndex, int toIndex, char key)
 此方法使用二分查找算法在指定字符数组的范围内搜索指定值。  | 
| 6 | static int binarySearch(double[] a, double key)
 此方法使用二进制搜索算法在指定的双精度数组中搜索指定的值。  | 
| 7 | static int binarySearch(double[] a, int fromIndex, int toIndex, double key)
 此方法使用二分查找算法在指定的双精度数组范围内搜索指定值。  | 
| 8 | static int binarySearch(float[] a, float key)
 此方法使用二进制搜索算法在指定的浮点数数组中搜索指定值。  | 
| 9 | static int binarySearch(float[] a, int fromIndex, int toIndex, float key)
 此方法使用二分查找算法在指定浮点数数组的范围内搜索指定值。  | 
| 10 | static int binarySearch(int[] a, int key)
 此方法使用二进制搜索算法在指定的整数数组中搜索指定的值。  | 
| 11 | static int binarySearch(int[] a, int fromIndex, int toIndex, int key)
 此方法使用二进制搜索算法在指定整数数组的范围内搜索指定值。  | 
| 12 | static int binarySearch(long[] a, int fromIndex, int toIndex, long key)
 此方法使用二进制搜索算法在指定的 long 数组的范围内搜索指定值。  | 
| 13 | static int binarySearch(long[] a, long key)
 此方法使用二分查找算法在指定的 long 数组中搜索指定的值。  | 
| 14 |  static int binarySearch(Object[] a, int fromIndex, int toIndex, Object key)
 此方法使用二分搜索算法在指定数组的范围内搜索指定对象。  | 
| 15 |  static int binarySearch(Object[] a, Object key)
 该方法使用二分查找算法在指定数组中查找指定对象。  | 
| 16 |  static int binarySearch(short[] a, int fromIndex, int toIndex, short key)
 此方法使用二分查找算法在指定的 short 数组的范围内搜索指定的值。  | 
| 17 | static int binarySearch(short[] a, short key)
 该方法使用二分查找算法在指定的shorts数组中查找指定的值。  | 
| 18 | static  该方法使用二分查找算法在指定数组的范围内查找指定对象。  | 
| 19 | static  该方法使用二分查找算法在指定数组中查找指定对象。  | 
| 20 | static boolean[] copyOf(boolean[] original, int newLength)
 此方法复制指定的数组,用 false 截断或填充(如有必要),使副本具有指定的长度。  | 
| 21 | static byte[] copyOf(byte[] original, int newLength)
 此方法复制指定的数组,截断或用零填充(如有必要),使副本具有指定的长度。  | 
| 22 | static char[] copyOf(char[] original, int newLength)
 此方法复制指定的数组,用空字符截断或填充(如有必要),因此副本具有指定的长度。  | 
| 23 | static double[] copyOf(double[] original, int newLength)
 此方法复制指定的数组,截断或用零填充(如有必要),使副本具有指定的长度。  | 
| 24 | static float[] copyOf(float[] original, int newLength)
 此方法复制指定的数组,截断或用零填充(如有必要),因此副本具有指定的长度。  | 
| 25 | static int[] copyOf(int[] original, int newLength)
 此方法复制指定的数组,截断或用零填充(如有必要),使副本具有指定的长度。  | 
| 26 | static long[] copyOf(long[] original, int newLength)
 此方法复制指定的数组,截断或用零填充(如有必要),因此副本具有指定的长度。  | 
| 27 | static short[] copyOf(short[] original, int newLength)
 此方法复制指定的数组,截断或用零填充(如有必要),使副本具有指定的长度。  | 
| 28 | static  此方法复制指定的数组,截断或用空值填充(如有必要),使副本具有指定的长度。  | 
| 29 | static  此方法复制指定的数组,截断或用空值填充(如有必要),使副本具有指定的长度。  | 
| 30 | static boolean[] copyOfRange(boolean[] original, int from, int to)
 此方法将指定数组的指定范围复制到一个新数组中。  | 
| 31 | static byte[] copyOfRange(byte[] original, int from, int to)
 该方法将指定数组的指定范围复制到一个新数组中。  | 
| 32 | static char[] copyOfRange(char[] original, int from, int to)
 此方法将指定数组的指定范围复制到一个新数组中。  | 
| 33 | static double[] copyOfRange(double[] original, int from, int to)
 该方法将指定数组的指定范围复制到一个新数组中。  | 
| 34 | static float[] copyOfRange(float[] original, int from, int to)
 此方法将指定数组的指定范围复制到一个新数组中。  | 
| 35 | static int[] copyOfRange(int[] original, int from, int to)
 该方法将指定数组的指定范围复制到一个新数组中。  | 
| 36 | static long[] copyOfRange(long[] original, int from, int to)
 此方法将指定数组的指定范围复制到一个新数组中。  | 
| 37 | static short[] copyOfRange(short[] original, int from, int to)
 该方法将指定数组的指定范围复制到一个新数组中。  | 
| 38 | static  该方法将指定数组的指定范围复制到一个新数组中。  | 
| 39 | static  该方法将指定数组的指定范围复制到一个新数组中。  | 
| 40 | static boolean deepEquals(Object[] a1, Object[] a2)
 如果两个指定的数组彼此深度相等,则此方法返回 true。  | 
| 41 | static int deepHashCode(Object[] a) 
 T他的方法根据指定数组的"深层内容"返回一个哈希码。  | 
| 42 | static String deepToString(Object[] a)
 此方法返回指定数组的"深层内容"的字符串表示形式。  | 
| 43 | static boolean equals(boolean[] a, boolean[] a2)
 如果两个指定的布尔数组彼此相等,则此方法返回 true。  | 
| 44 | static boolean equals(byte[] a, byte[] a2)
 如果两个指定的字节数组彼此相等,则此方法返回 true。  | 
| 45 | static boolean equals(char[] a, char[] a2)
 如果两个指定的字符数组彼此相等,则此方法返回 true。  | 
| 46 | static boolean equals(double[] a, double[] a2)
 如果两个指定的双精度数组彼此相等,则此方法返回 true。  | 
| 47 | static boolean equals(float[] a, float[] a2)
 如果两个指定的浮点数组彼此相等,则此方法返回 true。  | 
| 48 | static boolean equals(int[] a, int[] a2)
 如果两个指定的 int 数组彼此相等,则此方法返回 true。  | 
| 49 | static boolean equals(long[] a, long[] a2)
 如果两个指定的 long 数组彼此相等,则此方法返回 true。  | 
| 50 | static boolean equals(Object[] a, Object[] a2)
 如果两个指定的 Objects 数组彼此相等,则此方法返回 true。  | 
| 51 | static boolean equals(short[] a, short[] a2)
 如果指定的两个 short 数组彼此相等,则此方法返回 true。  | 
| 52 | static void fill(boolean[] a, boolean val)
 此方法将指定的布尔值分配给指定的布尔数组的每个元素。  | 
| 53 | static void fill(boolean[] a, int fromIndex, int toIndex, boolean val)
 此方法将指定的布尔值分配给指定布尔数组的指定范围内的每个元素。  | 
| 54 | static void fill(byte[] a, byte val) 
 此方法将指定的字节值分配给指定字节数组的每个元素。  | 
| 55 | static void fill(byte[] a, int fromIndex, int toIndex, byte val)
 此方法将指定的字节值分配给指定字节数组的指定范围的每个元素。  | 
| 56 | static void fill(char[] a, char val) 
 此方法将指定的 char 值分配给指定的 chars 数组的每个元素。  | 
| 57 | static void fill(char[] a, int fromIndex, int toIndex, char val)
 此方法将指定的字符值分配给指定字符数组的指定范围的每个元素。  | 
| 58 | static void fill(double[] a, double val)
 此方法将指定的 double 值分配给指定的 double 数组的每个元素。  | 
| 59 | static void fill(double[] a, int fromIndex, int toIndex, double val)
 此方法将指定的 double 值分配给指定的 double 数组的指定范围内的每个元素。  | 
| 60 | static void fill(float[] a, float val) 
 此方法将指定的浮点值分配给指定浮点数组的每个元素。  | 
| 61 | static void fill(float[] a, int fromIndex, int toIndex, float val)
 此方法将指定的浮点值分配给指定浮点数组的指定范围的每个元素。  | 
| 62 | static void fill(int[] a, int val) 
 此方法将指定的 int 值分配给指定的 int 数组的每个元素。  | 
| 63 | static void fill(int[] a, int fromIndex, int toIndex, int val)
 此方法将指定的 int 值分配给指定的 int 数组的指定范围的每个元素。  | 
| 64 | static void fill(long[] a, int fromIndex, int toIndex, long val)
 此方法将指定的 long 值分配给指定 long 数组的指定范围内的每个元素。  | 
| 65 | static void fill(long[] a, long val) 
 此方法将指定的 long 值分配给指定的 long 数组的每个元素。  | 
| 66 | static void fill(Object[] a, int fromIndex, int toIndex, Object val)
 此方法将指定的 Object 引用分配给指定的 Objects 数组的指定范围内的每个元素。  | 
| 67 | static void fill(Object[] a, Object val)
 此方法将指定的 Object 引用分配给指定的 Objects 数组的每个元素。  | 
| 68 | static void fill(short[] a, int fromIndex, int toIndex, short val)
 此方法将指定的 short 值分配给指定的 short 数组的指定范围的每个元素。  | 
| 69 | static void fill(short[] a, short val) 
 此方法将指定的 short 值分配给指定的 short 数组的每个元素。  | 
| 70 | static int hashCode(boolean[] a) 
 该方法根据指定数组的内容返回一个哈希码。  | 
| 71 | static int hashCode(byte[] a) 
 此方法根据指定数组的内容返回一个哈希码。  | 
| 72 | static int hashCode(char[] a) 
 该方法根据指定数组的内容返回一个哈希码。  | 
| 73 | static int hashCode(double[] a)
 此方法根据指定数组的内容返回一个哈希码。  | 
| 74 | static int hashCode(float[] a) 
 该方法根据指定数组的内容返回一个哈希码。  | 
| 75 | static int hashCode(int[] a)
 此方法根据指定数组的内容返回一个哈希码。  | 
| 76 | static int hashCode(long[] a) 
 该方法根据指定数组的内容返回一个哈希码。  | 
| 77 | static int hashCode(Object[] a) 
 此方法根据指定数组的内容返回一个哈希码。  | 
| 78 | static int hashCode(short[] a) 
 该方法根据指定数组的内容返回一个哈希码。  | 
| 79 | static void sort(byte[] a)
 此方法将指定的字节数组按数字升序排序。  | 
| 80 | static void sort(byte[] a, int fromIndex, int toIndex)
 该方法将指定字节数组的指定范围按数字升序排序。  | 
| 81 | static void sort(char[] a)
 此方法将指定的字符数组按数字升序排序。  | 
| 82 | static void sort(char[] a, int fromIndex, int toIndex)
 该方法将指定字符数组的指定范围按数字升序排序。  | 
| 83 | static void sort(double[] a)
 此方法将指定的双精度数组按数字升序排序。  | 
| 84 | static void sort(double[] a, int fromIndex, int toIndex)
 该方法将指定的 doubles 数组的指定范围按数字升序排序。  | 
| 85 | static void sort(float[] a)
 此方法将指定的浮点数数组按数字升序排序。  | 
| 86 | static void sort(float[] a, int fromIndex, int toIndex)
 该方法将指定的浮点数数组的指定范围按数字升序排序。  | 
| 87 | static void sort(int[] a)
 此方法将指定的整数数组按数字升序排序。  | 
| 88 | static void sort(int[] a, int fromIndex, int toIndex)
 此方法将指定整数数组的指定范围按数字升序排序。  | 
| 89 | static void sort(long[] a)
 此方法将指定的 long 数组按数字升序排序。  | 
| 90 | static void sort(long[] a, int fromIndex, int toIndex)
 该方法将指定的longs数组的指定范围按数字升序排序。  | 
| 91 |  static void sort(Object[] a)
 此方法根据其元素的自然顺序对指定的对象数组进行升序排序。  | 
| 92 | static void sort(Object[] a, int fromIndex, int toIndex)
 该方法将指定范围的指定对象数组按照其元素的自然顺序升序排序。  | 
| 93 | static void sort(short[] a)
 此方法将指定的 short 数组按数字升序排序。  | 
| 94 | static void sort(short[] a, int fromIndex, int toIndex)
 该方法将指定的shorts数组的指定范围按数字升序排序。  | 
| 95 | static  该方法根据指定的比较器引出的顺序对指定的对象数组进行排序。  | 
| 96 | static  该方法根据指定比较器引出的顺序对指定范围内的指定对象进行排序。  | 
| 97 | static String toString(boolean[] a)
 此方法返回指定布尔数组内容的字符串表示形式。  | 
| 98 | static String toString(byte[] a) 
 此方法返回指定字节数组内容的字符串表示形式。  | 
| 99 | static String toString(char[] a) 
 此方法返回指定字符数组内容的字符串表示形式。  | 
| 100 | static String toString(double[] a)
 此方法返回指定双精度数组内容的字符串表示形式。  | 
| 101 | static String toString(float[] a) 
 此方法返回指定浮点数数组内容的字符串表示形式。  | 
| 102 | static String toString(int[] a) 
 此方法返回指定整数数组内容的字符串表示形式。  | 
| 103 | static String toString(long[] a) 
 此方法返回指定 long 数组内容的字符串表示形式。  | 
| 104 | static String toString(Object[] a)
 此方法返回指定整数数组内容的字符串表示形式。  | 
| 105 | static String toString(short[] a) 
 此方法返回指定shorts 数组内容的字符串表示形式。  | 
这个类继承了以下类的方法 −
相关
视频
RELATED VIDEOS
科技资讯
1
2
3
4
5
6
7
8
9
精选课程
							
							共5课时
17.2万人学习
							
							共49课时
77万人学习
							
							共29课时
61.7万人学习
							
							共25课时
39.3万人学习
							
							共43课时
70.9万人学习
							
							共25课时
61.6万人学习
							
							共22课时
23万人学习
							
							共28课时
33.9万人学习
							
							共89课时
125万人学习