Java Utility Library

Java.util.Arrays Class



Java Arrays Class

Java.util package provides a Arrays class which contains a static factory that allows arrays to be viewed as lists. The class contains various methods for manipulating arrays like sorting and searching. The methods in this class throw a NullPointerException, if the specified array reference is null.

Class declaration

The declaration of java.util.Arrays class is:

public class Arrays
  extends Object

java.util.Arrays Methods

The java.util.Arrays class has a number of methods which are listed below:

Member Methods

S.NMethods & Description
1. static <T> List<T> asList(T...a)
Returns a fixed-size list backed by the specified array.
2. static int binarySearch(byte[] a, byte key)
Searches the specified array of bytes for the specified value using the binary search algorithm.
3. static int binarySearch(byte[] a, int fromIndex, int toIndex, byte key)
Searches a range of the specified array of bytes for the specified value using the binary search algorithm.
4. static int binarySearch(char[] a, char key)
Searches the specified array of chars for the specified value using the binary search algorithm.
5. static int binarySearch(char[] a, int fromIndex, int toIndex, char key)
Searches a range of the specified array of chars for the specified value using the binary search algorithm.
6. static int binarySearch(double[] a, double key)
Searches the specified array of doubles for the specified value using the binary search algorithm.
7. static int binarySearch(double[] a, int fromIndex, int toIndex, double key)
Searches a range of the specified array of doubles for the specified value using the binary search algorithm.
8. static int binarySearch(float[] a, float key)
Searches the specified array of floats for the specified value using the binary search algorithm.
9. static int binarySearch(float[] a, int fromIndex, int toIndex, float key)
Searches a range of the specified array of floats for the specified value using the binary search algorithm.
10. static int binarySearch(int[] a, int key)
Searches the specified array of ints for the specified value using the binary search algorithm.
11. static int binarySearch(int[] a, int fromIndex, int toIndex, int key)
Searches a range of the specified array of ints for the specified value using the binary search algorithm.
12. static int binarySearch(long[] a, long key)
Searches the specified array of longs for the specified value using the binary search algorithm.
13. static int binarySearch(long[] a, int fromIndex, int toIndex, long key)
Searches a range of the specified array of longs for the specified value using the binary search algorithm.
14. static int binarySearch(Object[] a, Object key)
Searches the specified array for the specified object using the binary search algorithm.
15. static int binarySearch(Object[] a, int fromIndex, int toIndex, Object key)
Searches a range of the specified array for the specified object using the binary search algorithm.
16. static int binarySearch(short[] a, short key)
Searches the specified array of shorts for the specified value using the binary search algorithm.
17. static int binarySearch(short[] a, int fromIndex, int toIndex, short key)
Searches a range of the specified array of shorts for the specified value using the binary search algorithm.
18. static <T> int binarySearch(T[] a, T key, Comparator<? super T> c)
Searches the specified array for the specified object using the binary search algorithm.
19. static <T> int binarySearch(T[] a, int fromIndex, int toIndex, T key, Comparator<? super T> c)
Searches a range of the specified array for the specified object using the binary search algorithm.
20. static boolean[] copyOf(boolean[] original, int newLength)
Copies the specified array, truncating or padding with false (if necessary) so the copy has the specified length.
21. static byte[] copyOf(byte[] original, int newLength)
Copies the specified array, truncating or padding with zeros (if necessary) so the copy has the specified length.
22. static char[] copyOf(char[] original, int newLength)
Copies the specified array, truncating or padding with null characters (if necessary) so the copy has the specified length.
23. static double[] copyOf(double[] original, int newLength)
Copies the specified array, truncating or padding with zeros (if necessary) so the copy has the specified length.
24. static float[] copyOf(float[] original, int newLength)
Copies the specified array, truncating or padding with zeros (if necessary) so the copy has the specified length.
25. static int[] copyOf(int[] original, int newLength)
Copies the specified array, truncating or padding with zeros (if necessary) so the copy has the specified length.
26. static long[] copyOf(long[] original, int newLength)
Copies the specified array, truncating or padding with zeros (if necessary) so the copy has the specified length.
27. static short[] copyOf(short[] original, int newLength)
Copies the specified array, truncating or padding with zeros (if necessary) so the copy has the specified length.
28. static <T> T[] copyOf(T[] original, int newLength)
Copies the specified array, truncating or padding with nulls (if necessary) so the copy has the specified length.
29. static <T,U> T[] copyOf(U[] original, int newLength, Class<? extends T[]> newType)
Copies the specified array, truncating or padding with nulls (if necessary) so the copy has the specified length.
30. static boolean[] copyOfRange(boolean[] original, int from, int to)
Copies the specified range of the specified array into a new array.
31. static byte[] copyOfRange(byte[] original, int from, int to)
Copies the specified range of the specified array into a new array.
32. static char[] copyOfRange(char[] original, int from, int to)
Copies the specified range of the specified array into a new array.
33. static double[] copyOfRange(double[] original, int from, int to)
Copies the specified range of the specified array into a new array.
34. static float[] copyOfRange(float[] original, int from, int to)
Copies the specified range of the specified array into a new array.
35. static int[] copyOfRange(int[] original, int from, int to)
Copies the specified range of the specified array into a new array.
36. static long[] copyOfRange(long[] original, int from, int to)
Copies the specified range of the specified array into a new array.
37. static short[] copyOfRange(short[] original, int from, int to)
Copies the specified range of the specified array into a new array.
38. static <T> T[] copyOfRange(T[] original, int from, int to)
Copies the specified range of the specified array into a new array.
39. static <T,U> T[] copyOfRange(U[] original, int from, int to, Class<? extends T[]> newType)
Copies the specified range of the specified array into a new array.
40. static boolean deepEquals(Object[] a1, Object[] a2)
Returns true if the two specified arrays are deeply equal to one another.
41. static int deepHashCode(Object[] a)
Returns a hash code based on the "deep contents" of the specified array.
42. static String deepToString(Object[] a)
Returns a string representation of the "deep contents" of the specified array.
43. static boolean equals(boolean[] a, boolean[] b)
Returns true if the two specified arrays of booleans are equal to one another.
44. static boolean equals(byte[] a, byte[] b)
Returns true if the two specified arrays of bytes are equal to one another.
45. static boolean equals(char[] a, char[] b)
Returns true if the two specified arrays of chars are equal to one another.
46. static boolean equals(double[] a, double[] b)
Returns true if the two specified arrays of doubles are equal to one another.
47. static boolean equals(float[] a, float[] b)
Returns true if the two specified arrays of floats are equal to one another.
48. static boolean equals(int[] a, int[] b)
Returns true if the two specified arrays of ints are equal to one another.
49. static boolean equals(long[] a, long[] b)
Returns true if the two specified arrays of longs are equal to one another.
50. static boolean equals(Object[] a, Object[] b)
Returns true if the two specified arrays of Objects are equal to one another.
51. static boolean equals(short[] a, short[] b)
Returns true if the two specified arrays of shorts are equal to one another.
52. static void fill(boolean[] a, boolean val)
Assigns the specified boolean value to each element of the specified array of booleans.
53. static void fill(boolean[] a, int fromIndex, int toIndex, boolean val)
Assigns the specified boolean value to each element of the specified range of the specified array of booleans.
54. static void fill(byte[] a, byte val)
Assigns the specified byte value to each element of the specified array of bytes.
55. static void fill(byte[] a, int fromIndex, int toIndex, byte val)
Assigns the specified byte value to each element of the specified range of the specified array of bytes.
56. static void fill(char[] a, char val)
Assigns the specified char value to each element of the specified array of chars.
57. static void fill(char[] a, int fromIndex, int toIndex, char val)
Assigns the specified char value to each element of the specified range of the specified array of chars.
58. static void fill(double[] a, double val)
Assigns the specified double value to each element of the specified array of doubles.
59. static void fill(double[] a, int fromIndex, int toIndex, double val)
Assigns the specified double value to each element of the specified range of the specified array of doubles.
60. static void fill(float[] a, float val)
Assigns the specified float value to each element of the specified array of floats.
61. static void fill(float[] a, int fromIndex, int toIndex, float val)
Assigns the specified float value to each element of the specified range of the specified array of floats.
62. static void fill(int[] a, int val)
Assigns the specified int value to each element of the specified array of ints.
63. static void fill(int[] a, int fromIndex, int toIndex, int val)
Assigns the specified int value to each element of the specified range of the specified array of ints.
64. static void fill(long[] a, long val)
Assigns the specified long value to each element of the specified array of longs.
65. static void fill(long[] a, int fromIndex, int toIndex, long val)
Assigns the specified long value to each element of the specified range of the specified array of longs.
66. static void fill(Object[] a, Object val)
Assigns the specified Object reference to each element of the specified array of Objects.
67. static void fill(Object[] a, int fromIndex, int toIndex,Object val)
Assigns the specified Object reference to each element of the specified range of the specified array of Objects.
68. static void fill(short[] a, short val)
Assigns the specified short value to each element of the specified array of shorts.
69. static void fill(short[] a, int fromIndex, int toIndex, short val)
Assigns the specified short value to each element of the specified range of the specified array of shorts.
70. static int hashCode(boolean[] a)
Returns a hash code based on the contents of the specified array.
71. static int hashCode(byte[] a)
Returns a hash code based on the contents of the specified array.
72. static int hashCode(char[] a)
Returns a hash code based on the contents of the specified array.
73. static int hashCode(double[] a)
Returns a hash code based on the contents of the specified array.
74. static int hashCode(float[] a)
Returns a hash code based on the contents of the specified array.
75. static int hashCode(int[] a)
Returns a hash code based on the contents of the specified array.
76. static int hashCode(long[] a)
Returns a hash code based on the contents of the specified array.
77. static int hashCode(Object[] a)
Returns a hash code based on the contents of the specified array.
78. static int hashCode(short[] a)
Returns a hash code based on the contents of the specified array.
79. static void parallelPrefix(double[] array, DoubleBinaryOperator op)
Cumulates, in parallel, each element of the given array in place, using the supplied function.
80. static void parallelPrefix(double[] array, int fromIndex, int toIndex, DoubleBinaryOperator op)
Performs parallelPrefix(double[], DoubleBinaryOperator) for the given subrange of the array.
81. static void parallelPrefix(int[] array, IntBinaryOperator op)
Cumulates, in parallel, each element of the given array in place, using the supplied function.
82. static void parallelPrefix(int[] array, int fromIndex, int toIndex, IntBinaryOperator op)
Performs parallelPrefix(int[], IntBinaryOperator) for the given subrange of the array.
83. static void parallelPrefix(long[] array, LongBinaryOperator op)
Cumulates, in parallel, each element of the given array in place, using the supplied function.
84. static void parallelPrefix(long[] array, int fromIndex, int toIndex, LongBinaryOperator op)
Performs parallelPrefix(long[], LongBinaryOperator) for the given subrange of the array.
85. static <T> void parallelPrefix(T[] array, BinaryOperator<T> op)
Cumulates, in parallel, each element of the given array in place, using the supplied function.
86. static <T> void parallelPrefix(T[] array, int fromIndex, int toIndex, BinaryOperator<T> op)
Performs parallelPrefix(Object[], BinaryOperator) for the given subrange of the array.
87. static void parallelSetAll(double[] array, IntToDoubleFunction generator)
Set all elements of the specified array, in parallel, using the provided generator function to compute each element.
88. static void parallelSetAll(int[] array, IntUnaryOperator generator)
Set all elements of the specified array, in parallel, using the provided generator function to compute each element.
89. static void parallelSetAll(long[] array, IntToLongFunction generator)
Set all elements of the specified array, in parallel, using the provided generator function to compute each element.
90. static <T> void parallelSetAll(T[] array, IntFunction<? extends T> generator)
Set all elements of the specified array, in parallel, using the provided generator function to compute each element.
91. static void parallelSort(byte[] a)
Sorts the specified array into ascending numerical order.
92. static void parallelSort(byte[] a, int fromIndex, int toIndex)
Sorts the specified range of the array into ascending numerical order.
93. static void parallelSort(char[] a)
Sorts the specified array into ascending numerical order.
94. static void parallelSort(char[] a, int fromIndex, int toIndex)
Sorts the specified range of the array into ascending numerical order.
95. static void parallelSort(double[] a)
Sorts the specified array into ascending numerical order.
96. static void parallelSort(double[] a, int fromIndex, int toIndex)
Sorts the specified range of the array into ascending numerical order.
97. static void parallelSort(float[] a)
Sorts the specified array into ascending numerical order.
98. static void parallelSort(float[] a, int fromIndex, int toIndex)
Sorts the specified range of the array into ascending numerical order.
99. static void parallelSort(int[] a)
Sorts the specified array into ascending numerical order.
100. static void parallelSort(int[] a, int fromIndex, int toIndex)
Sorts the specified range of the array into ascending numerical order.
101. static void parallelSort(long[] a)
Sorts the specified array into ascending numerical order.
102. static void parallelSort(long[] a, int fromIndex, int toIndex)
Sorts the specified range of the array into ascending numerical order.
103. static void parallelSort(short[] a)
Sorts the specified array into ascending numerical order.
104. static void parallelSort(short[] a, int fromIndex, int toIndex)
Sorts the specified range of the array into ascending numerical order.
105. static <T extends Comparable<? super T>> void parallelSort(T[] a)
Sorts the specified array of objects into ascending order, according to the natural ordering of its elements.
106. static <T> void parallelSort(T[] a, Comparator<? super T> cmp)
Sorts the specified array of objects according to the order induced by the specified comparator.
107. static <T extends Comparable<? super T>> void parallelSort(T[] a, int fromIndex, int toIndex)
Sorts the specified range of the specified array of objects into ascending order, according to the natural ordering of its elements.
108. static <T> void parallelSort(T[] a, int fromIndex, int toIndex, Comparator<? super T> cmp)
Sorts the specified range of the specified array of objects according to the order induced by the specified comparator.
109. static void setAll(double[] array, IntToDoubleFunction generator)
Set all elements of the specified array, using the provided generator function to compute each element.
110. static void setAll(int[] array, IntUnaryOperator generator)
Set all elements of the specified array, using the provided generator function to compute each element.
111. static void setAll(long[] array, IntToLongFunction generator)
Set all elements of the specified array, using the provided generator function to compute each element.
112. static <T> void setAll(T[] array, IntFunction<? extends T> generator)
Set all elements of the specified array, using the provided generator function to compute each element.
113. static void sort(byte[] a)
Sorts the specified array into ascending numerical order.
114. static void sort(byte[] a, int fromIndex, int toIndex)
Sorts the specified range of the array into ascending order.
115. static void sort(char[] a)
Sorts the specified array into ascending numerical order.
116. static void sort(char[] a, int fromIndex, int toIndex)
Sorts the specified range of the array into ascending order.
117. static void sort(double[] a)
Sorts the specified array into ascending numerical order.
118. static void sort(double[] a, int fromIndex, int toIndex)
Sorts the specified range of the array into ascending order.
119. static void sort(float[] a)
Sorts the specified array into ascending numerical order.
120. static void sort(float[] a, int fromIndex, int toIndex)
Sorts the specified range of the array into ascending order.
121. static void sort(int[] a)
Sorts the specified array into ascending numerical order.
122. static void sort(int[] a, int fromIndex, int toIndex)
Sorts the specified range of the array into ascending order.
123. static void sort(long[] a)
Sorts the specified array into ascending numerical order.
124. static void sort(long[] a, int fromIndex, int toIndex)
Sorts the specified range of the array into ascending order.
125. static void sort(Object[] a)
Sorts the specified array of objects into ascending order, according to the natural ordering of its elements.
126. static void sort(Object[] a, int fromIndex, int toIndex)
Sorts the specified range of the specified array of objects into ascending order, according to the natural ordering of its elements.
127. static void sort(short[] a)
Sorts the specified array into ascending numerical order.
128. static void sort(short[] a, int fromIndex, int toIndex)
Sorts the specified range of the array into ascending order.
129. static <T> void sort(T[] a, Comparator<? super T> c)
Sorts the specified array of objects according to the order induced by the specified comparator.
130. static <T> void sort(T[] a, int fromIndex, int toIndex, Comparator<? super T> c)
Sorts the specified range of the specified array of objects according to the order induced by the specified comparator.
131. static Spliterator.OfDouble spliterator(double[] array)
Returns a Spliterator.OfDouble covering all of the specified array.
132. static Spliterator.OfDouble spliterator(double[] array, int startInclusive, int endExclusive)
Returns a Spliterator.OfDouble covering the specified range of the specified array.
133. static Spliterator.OfInt spliterator(int[] array)
Returns a Spliterator.OfInt covering all of the specified array.
134. static Spliterator.OfInt spliterator(int[] array, int startInclusive, int endExclusive)
Returns a Spliterator.OfInt covering the specified range of the specified array.
135. static Spliterator.OfLong spliterator(long[] array)
Returns a Spliterator.OfLong covering all of the specified array.
136. static Spliterator.OfLong spliterator(long[] array, int startInclusive, int endExclusive)
Returns a Spliterator.OfLong covering the specified range of the specified array.
137. static <T> Spliterator<T> spliterator(T[] array)
Returns a Spliterator covering all of the specified array.
138. static <T> Spliterator<T> spliterator(T[] array, int startInclusive, int endExclusive)
Returns a Spliterator covering the specified range of the specified array.
139. static DoubleStream stream(double[] array)
Returns a sequential DoubleStream with the specified array as its source.
140. static DoubleStream stream(double[] array, int startInclusive, int endExclusive)
Returns a sequential DoubleStream with the specified range of the specified array as its source.
141. static IntStream stream(int[] array)
Returns a sequential IntStream with the specified array as its source.
142. static IntStream stream(int[] array, int startInclusive, int endExclusive)
Returns a sequential IntStream with the specified range of the specified array as its source.
143. static LongStream stream(long[] array)
Returns a sequential LongStream with the specified array as its source.
144. static LongStream stream(long[] array, int startInclusive, int endExclusive)
Returns a sequential LongStream with the specified range of the specified array as its source.
145. static <T> Stream<T> stream(T[] array)
Returns a sequential Stream with the specified array as its source.
146. static <T> Stream<T> stream(T[] array, int startInclusive, int endExclusive)
Returns a sequential Stream with the specified range of the specified array as its source.
147. static String toString(boolean[] a)
Returns a string representation of the contents of the specified array.
148. static String toString(byte[] a)
Returns a string representation of the contents of the specified array.
149. static String toString(char[] a)
Returns a string representation of the contents of the specified array.
150. static String toString(double[] a)
Returns a string representation of the contents of the specified array.
151. static String toString(float[] a)
Returns a string representation of the contents of the specified array.
152. static String toString(int[] a)
Returns a string representation of the contents of the specified array.
153. static String toString(long[] a)
Returns a string representation of the contents of the specified array.
154. static String toString(Object[] a)
Returns a string representation of the contents of the specified array.
155. static String toString(short[] a)
Returns a string representation of the contents of the specified array.

Methods inherited

This class inherits the methods of following class:

  • java.lang.Object