Java Arrays 类

Java.util 包提供了一个 Arrays 类,其中包含允许将数组视为列表的静态工厂。该类包含各种操作数组的方法,例如排序和搜索。如果指定的数组引用为 null,该类中的方法将抛出 NullPointerException

类声明

java.util.Arrays 类的声明为:

public class BitSet
  extends Object
    implements Cloneable, Serializable

java.util.Arrays 方法

java.util.Arrays 类有许多方法,如下所列:

成员方法

序号方法&描述
1.static <T> List<T> asList(T...a)
返回由指定数组支持的固定大小列表.
2. static int binarySearch(byte[] a, byte key)
使用二分搜索算法在指定的字节数组中搜索指定的值.
3.static int binarySearch(byte[] a, int fromIndex, int toIndex, byte key)
搜索范围使用二分搜索算法获取指定值的指定字节数组.
4.staticint 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, long key)
使用二分搜索算法在指定的 long 数组中搜索指定的值.
13.static int binarySearch(long[] a, int fromIndex, int toIndex, long key)
搜索指定范围内的 long 数组使用二分搜索算法查找指定值.
14.static int binarySearch(Object[ ] a, Object key)
使用二分查找算法在指定数组中查找指定对象.
15.static int binarySearch(Object[] a, int fromIndex, int toIndex, Object key)
使用以下命令在指定数组的范围内搜索指定对象二分查找算法.
16.static int binarySearch(short[] a,short key )
使用二分搜索算法在指定的 Shorts 数组中搜索指定的值.
17.static int binarySearch(short[] a, int fromIndex, int toIndex, Short key)
使用以下命令在指定的 Shorts 数组范围内搜索指定值二分查找算法.
18.static <T> int binarySearch(T[] a, T key , Comparator<? super T> c)
使用二分搜索算法在指定数组中搜索指定对象.
19.static <T> int binarySearch(T[] a, int fromIndex, int toIndex, T key, Comparator<? super T> c)
搜索指定数组的范围使用二分查找算法查找指定对象.
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 <T> T[] copyOf(T[] Original, int newLength)
复制指定数组,进行截断或填充带有空值(如果需要),以便副本具有指定的长度.
29.static <T ,U> T[] copyOf(U[] original, int newLength, Class<? extends T[]> newType)
复制指定的数组,截断或用空值填充(如果需要),以便副本具有指定的长度.
30.static boolean[] copyOfRange(boolean[] original, int from, int to)
复制指定范围将指定数组转换为新数组.
31.static byte[] copyOfRange(byte [] origin, 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[] origin, int from, int to)
将指定数组的指定范围复制到新数组中.
37.static short[] copyOfRange(short[]original,int from,int to)
将指定数组的指定范围复制到新数组中.
38.static <T> T [] copyOfRange(T[] original, int from, int to)
将指定数组的指定范围复制到新数组中.
39.static <T,U> T[] copyOfRange(U[] original, int from, int to, Class<?extends T[]> newType)
将指定数组的指定范围复制到新数组中.
40.static boolean deepEquals(Object[] a1, Object[] a2)
如果两个指定的数组深度相等,则返回 true。
41.static int deepHashCode(Object[] a)
返回基于指定数组的“深层内容”的哈希码.
42.static String deepToString(Object[] a)
返回指定数组“深层内容”的字符串表示形式.
43。static boolean equals(boolean[] a, boolean[] b)
如果两个指定的布尔数组等于 1,则返回 true另一个.
44.static boolean equals(byte[] a, byte[] b)
如果两个指定的字节数组彼此相等,则返回 true.
45.static boolean equals(char[] a, char[] b)
如果两个指定的字符数组彼此相等,则返回 true.
46.static boolean equals(double[] a, double[] b)
如果两个指定的双精度数组彼此相等,则返回 true.
47.static boolean equals(float[] a, float[] b)
如果两个指定的浮点数组彼此相等,则返回 true.
48.static boolean equals(int[] a, int[] b)
如果两个指定数组整数彼此相等.
49.static boolean equals(long[] a, long[] b)
如果两个指定的 long 数组彼此相等,则返回 true.
50.static boolean equals(Object[] a, Object[] b)
如果两个指定的对象数组彼此相等,则返回 true.
51.static boolean equals(short[] a,short[] b)
如果两个指定的短裤数组彼此相等,则返回 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 值分配给指定字符数组的每个元素.
57 .static void fill(char[] a, int fromIndex, int toIndex, char val)
分配指定的 char 值到指定字符数组的指定范围内的每个元素.
58.static void fill(double[] a, double val)
将指定的双精度值分配给指定双精度数组的每个元素.
59.static void fill(double[] a, int fromIndex, int toIndex, double val)
为每个值分配指定的 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 值赋给指定的每个元素指定整数数组的范围.
64.static void fill(long[] a , long val)
将指定的 long 值分配给指定 long 数组的每个元素.
65.static void fill(long[] a, int fromIndex, int toIndex, long val)
将指定的 long 值赋给指定范围内的每个元素指定的长整型数组.
66.static void fill(Object[] a, Object val)
将指定的对象引用分配给指定对象数组的每个元素.
67.static void fill(Object[] a, int fromIndex, int toIndex,Object val)
将指定的Object引用分配给指定的指定范围内的每个元素对象数组.
68.static void fill(short[] a, short val)
将指定的 Short 值分配给指定 Shorts 数组的每个元素.
69.static void fill(short[] a, int fromIndex, int toIndex, Short val)
将指定的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 parallelPrefix(double[] array, DoubleBinaryOperator op)
使用提供的函数并行累积给定数组的每个元素.
80.static void parallelPrefix(double[] array, int fromIndex, int toIndex, DoubleBinaryOperator op)
对数组的给定子范围执行parallelPrefix(double[], DoubleBinaryOperator).
81.static void parallelPrefix(int[] array, IntBinaryOperator op)
使用提供的函数并行累积给定数组的每个元素.
82.static void parallelPrefix(int[] array, int fromIndex, int toIndex, IntBinaryOperator op)
对数组的给定子范围执行parallelPrefix(int[], IntBinaryOperator).
83.static void parallelPrefix(long[] array, LongBinaryOperator op)
使用提供的函数并行累积给定数组的每个元素.
84.static void parallelPrefix(long[] array, int fromIndex, int toIndex, LongBinaryOperator op)
对数组的给定子范围执行parallelPrefix(long[], LongBinaryOperator).
85.static <T> void parallelPrefix(T[] array, BinaryOperator<T> op)
使用提供的并行累积给定数组的每个元素函数.
86.static <T> void parallelPrefix(T[] array, int fromIndex, int toIndex, BinaryOperator<T> op)
对数组的给定子范围执行parallelPrefix(Object[], BinaryOperator).
87.static void parallelSetAll(double[] array, IntToDoubleFunction generator)
使用提供的生成器函数并行设置指定数组的所有元素计算每个元素.
88.static void parallelSetAll(int[] array, IntUnaryOperator Generator )
使用提供的生成器函数并行设置指定数组的所有元素,以计算每个元素.
89.static void parallelSetAll(long[] array, IntToLongFunction generator)
使用提供的生成器函数并行设置指定数组的所有元素计算每个元素.
90.static <T> void parallelSetAll(T[] array, IntFunction< ? extends T> generator)
使用提供的生成器函数并行设置指定数组的所有元素来计算每个元素.
91.static void parallelSort(byte[] a)
将指定数组按照数字升序排序.
92.static void parallelSort(byte[] a, int fromIndex, int toIndex)
将指定范围的数组按数字升序排序.
93.static void parallelSort( char[] a)
将指定数组按升序排序.
94.static void parallelSort(char[] a, int fromIndex, int toIndex)
将指定范围的数组按数字升序排序.
95.static void parallelSort(double[] a)
将指定数组按升序排序.
96.static void parallelSort(double[] a, int fromIndex, int toIndex)
将指定范围的数组按升序排序.
97.static void parallelSort(float[] a)
将指定数组按数字升序排序.
98.static void parallelSort(float[] a, int fromIndex, int toIndex)
将指定范围的数组按数字升序排序.
99.static void parallelSort(int[] a)
将指定数组按升序排序.
100.static void parallelSort(int[] a, int fromIndex, int toIndex)
将指定范围的数组按数字升序排序.
101.static void parallelSort(long[] a)
将指定数组按数字升序排序.
102.static void parallelSort(long[] a, int fromIndex, int toIndex)
对指定范围进行排序将数组升序排列.
103.static void parallelSort(short[] a)
将指定数组按数字升序排序.
104.static void parallelSort(short[] a, int fromIndex, int toIndex)
将指定范围的数组按数字升序排序.
105.static <T extends Comparable<? super T>> void parallelSort(T[] a)
根据其元素的自然顺序,将指定的对象数组按升序排序.
106.static <T> void parallelSort(T[] a, Comparator<? super T> cmp)
对指定数组进行排序根据指定比较器引发的顺序排列对象.
107.static <T extends Comparable<? super T>> void parallelSort(T[] a, int fromIndex, int toIndex)
根据其元素的自然顺序,对指定对象数组的指定范围进行升序排序。
108.static <T> void parallelSort(T[] a, int fromIndex, int toIndex, Comparator<? super T> cmp)
根据指定比较器引发的顺序对指定对象数组的指定范围进行排序.
109。static void setAll(double[] array, IntToDoubleFunction Generator)
设置指定数组的所有元素,使用提供的生成器函数进行计算每个元素.
110.static void setAll(int[] array, IntUnaryOperator Generator)
设置指定数组的所有元素,使用提供的生成器函数计算每个元素.
111.static void setAll(long[] array, IntToLongFunction Generator)
设置指定数组的所有元素,使用提供的生成器函数计算每个元素。
112.static <T> void setAll(T[] array, IntFunction<?extendsT> generator)
设置指定数组的所有元素,使用提供的生成器函数计算每个元素.
113.static void sort(byte[] a)
将指定数组按数字升序排序.
114.static void sort(byte[] a, int fromIndex, int toIndex)
对指定的元素进行排序数组范围升序排列.
115.static void sort(char[] a )
将指定数组按升序排序.
116.static void sort(char[] a, int fromIndex, int toIndex)
对指定范围的数组进行升序排序.
117.static void sort(double[] a)
将指定数组按升序排序.
118.static void sort(double[] a, int fromIndex, int toIndex)
对指定范围的数组进行升序排序.
119.static void sort(float[] a)
将指定数组按升序排序.
120.static void sort(float[] a, int fromIndex, int toIndex)
对指定范围的数组进行升序排序.
121.static void sort(int[] a)
将指定数组按升序排序顺序.
122.static void sort(int[] a, int fromIndex, int toIndex )
将指定范围的数组按升序排序.
123.static void sort(long[] a)
将指定数组按照数字升序排序.
124.static void sort(long[] a, int fromIndex, int toIndex)
将指定范围的数组按升序排序。
125.static void sort(Object[] a)
排序根据其元素的自然顺序将指定的对象数组升序排列.
126.static void sort(Object[] a, int fromIndex, int toIndex)
根据其元素的自然顺序,对指定对象数组的指定范围进行升序排序。
127.static void sort(short[] a)
排序将指定数组按升序排列.
128.static void sort(short[] a , int fromIndex, int toIndex)
对指定范围的数组进行升序排序.
129.static <T> void sort(T[] a, Comparator<? super T> c)
根据指定比较器产生的顺序对指定的对象数组进行排序.
130.static <T> void sort(T[] a, int fromIndex, int toIndex, Comparator<?super T> c)
根据指定比较器产生的顺序对指定对象数组的指定范围进行排序.
131.static Spliterator.OfDouble spliterator(double[] array)
返回覆盖所有指定数组的 Spliterator.OfDouble。    
132.static Spliterator.OfDouble spliterator(double[] array, int startInclusive, int endExclusive)
返回覆盖指定数组的指定范围的 Spliterator.OfDouble.
133.static Spliterator.OfInt spliterator(int[] array)
返回覆盖所有指定数组的 Spliterator.OfInt.
134 .static Spliterator.OfInt spliterator(int[] array, int startInclusive, int endExclusive)
返回一个 Spliterator.OfInt 覆盖指定数组的指定范围.
135.static Spliterator.OfLong spliterator(long[ ] array)
返回覆盖所有指定数组的 Spliterator.OfLong.
136.static Spliterator.OfLong spliterator(long[] array, int startInclusive, int endExclusive)
返回覆盖指定数组的指定范围的 Spliterator.OfLong .
137.static <T> Spliterator<T> spliterator(T[] array)
返回一个Spliterator 覆盖所有指定数组.
138.static <T> Spliterator<T> spliterator(T[] array, int startInclusive, int endExclusive)
返回覆盖指定数组的指定范围的 Spliterator.
139.static DoubleStream Stream(double[] array)
返回以指定数组为源的顺序 DoubleStream.
140.static DoubleStream stream(double[] array, int startInclusive, int endExclusive)
返回一个以指定数组的指定范围为源的顺序 DoubleStream.
141.static IntStream Stream(int[] array)
返回以指定数组为源的顺序 IntStream.
142.static IntStream stream(int[] array, int startInclusive, int endExclusive)
返回一个以指定数组的指定范围为源的顺序 IntStream。
143.static Long Stream stream(long[]array)
返回一个以指定数组为源的顺序 LongStream.
144.static Long Stream stream(long[] array, int startInclusive, int endExclusive)
返回一个以指定数组的指定范围为源的顺序 LongStream.
145.static <T> Stream<T> stream(T[] array)
返回以指定数组为源的顺序 Stream。
146.static <T> Stream<T> stream(T[] array,int startInclusive,int endExclusive)
返回以指定数组的指定范围为源的顺序 Stream.
147.static String toString(boolean[] a)
返回指定数组内容的字符串表示形式.
148.static String toString(byte[] a)
返回指定数组内容的字符串表示形式。
149.static String toString(char[] a)
返回指定数组内容的字符串表示形式.
150.static String toString (double[] a)
返回指定数组内容的字符串表示形式.
151.static String toString(float[] a)
返回指定数组内容的字符串表示形式.
152.static String toString(int[] a)
返回指定内容的字符串表示形式数组.
153.static String toString(long[] a)
返回指定数组内容的字符串表示形式.
154.static String toString(Object[] a)
返回指定数组内容的字符串表示形式.
155.static String toString(short[] a)
返回指定数组内容的字符串表示形式.

继承的方法

该类继承了以下类的方法:

  • java.lang.Object