Class Arrays
Arrays contains static methods which operate on arrays.
Since
1.2
-
Method Summary
Modifier and TypeMethodDescriptionstatic <T> List<T> asList(T... array) Returns aListof the objects in the specified array.static intbinarySearch(byte[] array, byte value) Performs a binary search for the specified element in the specified ascending sorted array.static intbinarySearch(byte[] array, int startIndex, int endIndex, byte value) Performs a binary search for the specified element in a part of the specified sorted array.static intbinarySearch(char[] array, char value) Performs a binary search for the specified element in the specified sorted array.static intbinarySearch(char[] array, int startIndex, int endIndex, char value) Performs a binary search for the specified element in a part of the specified sorted array.static intbinarySearch(double[] array, double value) Performs a binary search for the specified element in the specified sorted array.static intbinarySearch(double[] array, int startIndex, int endIndex, double value) Performs a binary search for the specified element in a part of the specified sorted array.static intbinarySearch(float[] array, float value) Performs a binary search for the specified element in the specified sorted array.static intbinarySearch(float[] array, int startIndex, int endIndex, float value) Performs a binary search for the specified element in a part of the specified sorted array.static intbinarySearch(int[] array, int value) Performs a binary search for the specified element in the specified sorted array.static intbinarySearch(int[] array, int startIndex, int endIndex, int value) Performs a binary search for the specified element in a part of the specified sorted array.static intbinarySearch(long[] array, int startIndex, int endIndex, long value) Performs a binary search for the specified element in a part of the specified sorted array.static intbinarySearch(long[] array, long value) Performs a binary search for the specified element in the specified sorted array.static intbinarySearch(short[] array, int startIndex, int endIndex, short value) Performs a binary search for the specified element in a part of the specified sorted array.static intbinarySearch(short[] array, short value) Performs a binary search for the specified element in the specified sorted array.static intbinarySearch(Object[] array, int startIndex, int endIndex, Object object) Performs a binary search for the specified element in a part of the specified sorted array.static intbinarySearch(Object[] array, Object object) Performs a binary search for the specified element in the specified sorted array.static <T> intbinarySearch(T[] array, int startIndex, int endIndex, T object, Comparator<? super T> comparator) Performs a binary search for the specified element in a part of the specified sorted array using the Comparator to compare elements.static <T> intbinarySearch(T[] array, T object, Comparator<? super T> comparator) Performs a binary search for the specified element in the specified sorted array using the Comparator to compare elements.static boolean[]copyOf(boolean[] original, int newlen) static byte[]copyOf(byte[] original, int newlen) static char[]copyOf(char[] original, int newlen) static double[]copyOf(double[] original, int newlen) static float[]copyOf(float[] original, int newlen) static int[]copyOf(int[] original, int newlen) static long[]copyOf(long[] original, int newlen) static short[]copyOf(short[] original, int len) static <T> T[]copyOf(T[] original, int newLength) static <T> T[]static boolean[]copyOfRange(boolean[] original, int start, int end) Copies elements in original array to a new array, from index start(inclusive) to end(exclusive).static byte[]copyOfRange(byte[] original, int start, int end) Copies elements in original array to a new array, from index start(inclusive) to end(exclusive).static char[]copyOfRange(char[] original, int start, int end) Copies elements in original array to a new array, from index start(inclusive) to end(exclusive).static double[]copyOfRange(double[] original, int start, int end) Copies elements in original array to a new array, from index start(inclusive) to end(exclusive).static float[]copyOfRange(float[] original, int start, int end) Copies elements in original array to a new array, from index start(inclusive) to end(exclusive).static int[]copyOfRange(int[] original, int start, int end) Copies elements in original array to a new array, from index start(inclusive) to end(exclusive).static long[]copyOfRange(long[] original, int start, int end) Copies elements in original array to a new array, from index start(inclusive) to end(exclusive).static short[]copyOfRange(short[] original, int start, int end) Copies elements in original array to a new array, from index start(inclusive) to end(exclusive).static <T> T[]copyOfRange(T[] original, int from, int to) static <T,U> T[] copyOfRange(U[] original, int from, int to, Class<? extends T[]> newType) static booleandeepEquals(Object[] array1, Object[] array2) Returnstrueif the two given arrays are deeply equal to one another.static intdeepHashCode(Object[] array) Returns a hash code based on the "deep contents" of the given array.static StringdeepToString(Object[] array) Creates a "deep"Stringrepresentation of theObject[]passed, such that if the array contains other arrays, theStringrepresentation of those arrays is generated as well.static booleanequals(boolean[] array1, boolean[] array2) Compares the two arrays.static booleanequals(byte[] array1, byte[] array2) Compares the two arrays.static booleanequals(char[] array1, char[] array2) Compares the two arrays.static booleanequals(double[] array1, double[] array2) Compares the two arrays.static booleanequals(float[] array1, float[] array2) Compares the two arrays.static booleanequals(int[] array1, int[] array2) Compares the two arrays.static booleanequals(long[] array1, long[] array2) Compares the two arrays.static booleanequals(short[] array1, short[] array2) Compares the two arrays.static booleanCompares the two arrays.static voidfill(boolean[] array, boolean value) Fills the specified array with the specified element.static voidfill(boolean[] array, int start, int end, boolean value) Fills the specified range in the array with the specified element.static voidfill(byte[] array, byte value) Fills the specified array with the specified element.static voidfill(byte[] array, int start, int end, byte value) Fills the specified range in the array with the specified element.static voidfill(char[] array, char value) Fills the specified array with the specified element.static voidfill(char[] array, int start, int end, char value) Fills the specified range in the array with the specified element.static voidfill(double[] array, double value) Fills the specified array with the specified element.static voidfill(double[] array, int start, int end, double value) Fills the specified range in the array with the specified element.static voidfill(float[] array, float value) Fills the specified array with the specified element.static voidfill(float[] array, int start, int end, float value) Fills the specified range in the array with the specified element.static voidfill(int[] array, int value) Fills the specified array with the specified element.static voidfill(int[] array, int start, int end, int value) Fills the specified range in the array with the specified element.static voidfill(long[] array, int start, int end, long value) Fills the specified range in the array with the specified element.static voidfill(long[] array, long value) Fills the specified array with the specified element.static voidfill(short[] array, int start, int end, short value) Fills the specified range in the array with the specified element.static voidfill(short[] array, short value) Fills the specified array with the specified element.static voidFills the specified range in the array with the specified element.static voidFills the specified array with the specified element.static inthashCode(boolean[] array) Returns a hash code based on the contents of the given array.static inthashCode(byte[] array) Returns a hash code based on the contents of the given array.static inthashCode(char[] array) Returns a hash code based on the contents of the given array.static inthashCode(double[] array) Returns a hash code based on the contents of the given array.static inthashCode(float[] array) Returns a hash code based on the contents of the given array.static inthashCode(int[] array) Returns a hash code based on the contents of the given array.static inthashCode(long[] array) Returns a hash code based on the contents of the given array.static inthashCode(short[] array) Returns a hash code based on the contents of the given array.static intReturns a hash code based on the contents of the given array.static voidsort(byte[] array) Sorts the specified array in ascending numerical order.static voidsort(byte[] array, int start, int end) Sorts the specified range in the array in ascending numerical order.static voidsort(char[] array) Sorts the specified array in ascending numerical order.static voidsort(char[] array, int start, int end) Sorts the specified range in the array in ascending numerical order.static voidsort(double[] array) Sorts the specified array in ascending numerical order.static voidsort(double[] array, int start, int end) Sorts the specified range in the array in ascending numerical order.static voidsort(float[] array) Sorts the specified array in ascending numerical order.static voidsort(float[] array, int start, int end) Sorts the specified range in the array in ascending numerical order.static voidsort(int[] array) Sorts the specified array in ascending numerical order.static voidsort(int[] array, int start, int end) Sorts the specified range in the array in ascending numerical order.static voidsort(long[] array) Sorts the specified array in ascending numerical order.static voidsort(long[] array, int start, int end) Sorts the specified range in the array in ascending numerical order.static voidsort(short[] array) Sorts the specified array in ascending numerical order.static voidsort(short[] array, int start, int end) Sorts the specified range in the array in ascending numerical order.static voidSorts the specified array in ascending natural order.static voidSorts the specified range in the array in ascending natural order.static <T> voidsort(T[] array, int start, int end, Comparator<? super T> comparator) Sorts the specified range in the array using the specifiedComparator.static <T> voidsort(T[] array, Comparator<? super T> comparator) Sorts the specified array using the specifiedComparator.static StringtoString(boolean[] array) Creates aStringrepresentation of theboolean[]passed.static StringtoString(byte[] array) Creates aStringrepresentation of thebyte[]passed.static StringtoString(char[] array) Creates aStringrepresentation of thechar[]passed.static StringtoString(double[] array) Creates aStringrepresentation of thedouble[]passed.static StringtoString(float[] array) Creates aStringrepresentation of thefloat[]passed.static StringtoString(int[] array) Creates aStringrepresentation of theint[]passed.static StringtoString(long[] array) Creates aStringrepresentation of thelong[]passed.static StringtoString(short[] array) Creates aStringrepresentation of theshort[]passed.static StringCreates aStringrepresentation of theObject[]passed.
-
Method Details
-
asList
Returns a
Listof the objects in the specified array. The size of theListcannot be modified, i.e. adding and removing are unsupported, but the elements can be set. Setting an element modifies the underlying array.Parameters
array: the array.
Returns
a
Listof the elements of the specified array. -
binarySearch
public static int binarySearch(byte[] array, byte value) Performs a binary search for the specified element in the specified ascending sorted array. Searching in an unsorted array has an undefined result. It's also undefined which element is found if there are multiple occurrences of the same element.
Parameters
-
array: the sortedbytearray to search. -
value: thebyteelement to find.
Returns
- Returns:
- the non-negative index of the element, or a negative index which
is
-index - 1where the element would be inserted.
-
-
binarySearch
public static int binarySearch(char[] array, char value) Performs a binary search for the specified element in the specified sorted array.
Parameters
-
array: the sorted char array to search -
value: the char element to find
Returns
- Returns:
- the non-negative index of the element, or a negative index which is the -index - 1 where the element would be inserted
-
-
binarySearch
public static int binarySearch(double[] array, double value) Performs a binary search for the specified element in the specified sorted array.
Parameters
-
array: the sorted double array to search -
value: the double element to find
Returns
- Returns:
- the non-negative index of the element, or a negative index which is the -index - 1 where the element would be inserted
-
-
binarySearch
public static int binarySearch(float[] array, float value) Performs a binary search for the specified element in the specified sorted array.
Parameters
-
array: the sorted float array to search -
value: the float element to find
Returns
- Returns:
- the non-negative index of the element, or a negative index which is the -index - 1 where the element would be inserted
-
-
binarySearch
public static int binarySearch(int[] array, int value) Performs a binary search for the specified element in the specified sorted array.
Parameters
-
array: the sorted int array to search -
value: the int element to find
Returns
- Returns:
- the non-negative index of the element, or a negative index which is the -index - 1 where the element would be inserted
-
-
binarySearch
public static int binarySearch(long[] array, long value) Performs a binary search for the specified element in the specified sorted array.
Parameters
-
array: the sorted long array to search -
value: the long element to find
Returns
- Returns:
- the non-negative index of the element, or a negative index which is the -index - 1 where the element would be inserted
-
-
binarySearch
Performs a binary search for the specified element in the specified sorted array.
Parameters
-
array: the sorted Object array to search -
object: the Object element to find
Returns
- Returns:
the non-negative index of the element, or a negative index which is the -index - 1 where the element would be inserted
Throws
ClassCastException: @exception ClassCastException when an element in the array or the search element does not implement Comparable, or cannot be compared to each other
-
-
binarySearch
Performs a binary search for the specified element in the specified sorted array using the Comparator to compare elements.
Type parameter
T: type of objectParameters
-
array: the sorted Object array to search -
object: the char element to find -
comparator: the Comparator
Returns
- Returns:
the non-negative index of the element, or a negative index which is the -index - 1 where the element would be inserted
Throws
ClassCastException: @exception ClassCastException when an element in the array and the search element cannot be compared to each other using the Comparator
-
-
binarySearch
public static int binarySearch(short[] array, short value) Performs a binary search for the specified element in the specified sorted array.
Parameters
-
array: the sorted short array to search -
value: the short element to find
Returns
- Returns:
- the non-negative index of the element, or a negative index which is the -index - 1 where the element would be inserted
-
-
binarySearch
public static int binarySearch(byte[] array, int startIndex, int endIndex, byte value) Performs a binary search for the specified element in a part of the specified sorted array.
Parameters
-
array: the sorted byte array to search -
startIndex: the inclusive start index -
endIndex: the exclusive end index -
value: the byte element to find
Returns
- Returns:
the non-negative index of the element, or a negative index which is the -index - 1 where the element would be inserted
Throws
-
IllegalArgumentException: @throws IllegalArgumentException - if startIndex is bigger than endIndex -
ArrayIndexOutOfBoundsException: @throws ArrayIndexOutOfBoundsException - if startIndex is smaller than zero or or endIndex is bigger than length of array
Since
1.6
-
-
-
binarySearch
public static int binarySearch(char[] array, int startIndex, int endIndex, char value) Performs a binary search for the specified element in a part of the specified sorted array.
Parameters
-
array: the sorted char array to search -
startIndex: the inclusive start index -
endIndex: the exclusive end index -
value: the char element to find
Returns
- Returns:
the non-negative index of the element, or a negative index which is the -index - 1 where the element would be inserted
Throws
-
IllegalArgumentException: @throws IllegalArgumentException - if startIndex is bigger than endIndex -
ArrayIndexOutOfBoundsException: @throws ArrayIndexOutOfBoundsException - if startIndex is smaller than zero or or endIndex is bigger than length of array
Since
1.6
-
-
-
binarySearch
public static int binarySearch(double[] array, int startIndex, int endIndex, double value) Performs a binary search for the specified element in a part of the specified sorted array.
Parameters
-
array: the sorted double array to search -
startIndex: the inclusive start index -
endIndex: the exclusive end index -
value: the double element to find
Returns
- Returns:
the non-negative index of the element, or a negative index which is the -index - 1 where the element would be inserted
Throws
-
IllegalArgumentException: @throws IllegalArgumentException - if startIndex is bigger than endIndex -
ArrayIndexOutOfBoundsException: @throws ArrayIndexOutOfBoundsException - if startIndex is smaller than zero or or endIndex is bigger than length of array
Since
1.6
-
-
-
binarySearch
public static int binarySearch(float[] array, int startIndex, int endIndex, float value) Performs a binary search for the specified element in a part of the specified sorted array.
Parameters
-
array: the sorted float array to search -
startIndex: the inclusive start index -
endIndex: the exclusive end index -
value: the float element to find
Returns
- Returns:
the non-negative index of the element, or a negative index which is the -index - 1 where the element would be inserted
Throws
-
IllegalArgumentException: @throws IllegalArgumentException - if startIndex is bigger than endIndex -
ArrayIndexOutOfBoundsException: @throws ArrayIndexOutOfBoundsException - if startIndex is smaller than zero or or endIndex is bigger than length of array
Since
1.6
-
-
-
binarySearch
public static int binarySearch(int[] array, int startIndex, int endIndex, int value) Performs a binary search for the specified element in a part of the specified sorted array.
Parameters
-
array: the sorted int array to search -
startIndex: the inclusive start index -
endIndex: the exclusive end index -
value: the int element to find
Returns
- Returns:
the non-negative index of the element, or a negative index which is the -index - 1 where the element would be inserted
Throws
-
IllegalArgumentException: @throws IllegalArgumentException - if startIndex is bigger than endIndex -
ArrayIndexOutOfBoundsException: @throws ArrayIndexOutOfBoundsException - if startIndex is smaller than zero or or endIndex is bigger than length of array
Since
1.6
-
-
-
binarySearch
public static int binarySearch(long[] array, int startIndex, int endIndex, long value) Performs a binary search for the specified element in a part of the specified sorted array.
Parameters
-
array: the sorted long array to search -
startIndex: the inclusive start index -
endIndex: the exclusive end index -
value: the long element to find
Returns
- Returns:
the non-negative index of the element, or a negative index which is the -index - 1 where the element would be inserted
Throws
-
IllegalArgumentException: @throws IllegalArgumentException - if startIndex is bigger than endIndex -
ArrayIndexOutOfBoundsException: @throws ArrayIndexOutOfBoundsException - if startIndex is smaller than zero or or endIndex is bigger than length of array
Since
1.6
-
-
-
binarySearch
Performs a binary search for the specified element in a part of the specified sorted array.
Parameters
-
array: the sorted Object array to search -
startIndex: the inclusive start index -
endIndex: the exclusive end index -
object: the object element to find
Returns
- Returns:
the non-negative index of the element, or a negative index which is the -index - 1 where the element would be inserted
Throws
-
ClassCastException: @throws ClassCastException when an element in the array or the search element does not implement Comparable, or cannot be compared to each other -
IllegalArgumentException: @throws IllegalArgumentException - if startIndex is bigger than endIndex -
ArrayIndexOutOfBoundsException: @throws ArrayIndexOutOfBoundsException - if startIndex is smaller than zero or or endIndex is bigger than length of array
Since
1.6
-
-
-
binarySearch
public static <T> int binarySearch(T[] array, int startIndex, int endIndex, T object, Comparator<? super T> comparator) Performs a binary search for the specified element in a part of the specified sorted array using the Comparator to compare elements.
Type parameter
T: type of objectParameters
-
array: the sorted Object array to search -
startIndex: the inclusive start index -
endIndex: the exclusive end index -
object: the value element to find -
comparator: the Comparator
Returns
- Returns:
the non-negative index of the element, or a negative index which is the -index - 1 where the element would be inserted
Throws
-
ClassCastException: @throws ClassCastException when an element in the array and the search element cannot be compared to each other using the Comparator -
IllegalArgumentException: @throws IllegalArgumentException - if startIndex is bigger than endIndex -
ArrayIndexOutOfBoundsException: @throws ArrayIndexOutOfBoundsException - if startIndex is smaller than zero or or endIndex is bigger than length of array
Since
1.6
-
-
-
binarySearch
public static int binarySearch(short[] array, int startIndex, int endIndex, short value) Performs a binary search for the specified element in a part of the specified sorted array.
Parameters
-
array: the sorted short array to search -
startIndex: the inclusive start index -
endIndex: the exclusive end index -
value: the short element to find
Returns
- Returns:
the non-negative index of the element, or a negative index which is the -index - 1 where the element would be inserted
Throws
-
IllegalArgumentException: @throws IllegalArgumentException - if startIndex is bigger than endIndex -
ArrayIndexOutOfBoundsException: @throws ArrayIndexOutOfBoundsException - if startIndex is smaller than zero or or endIndex is bigger than length of array
Since
1.6
-
-
-
fill
public static void fill(byte[] array, byte value) Fills the specified array with the specified element.
Parameters
-
array: thebytearray to fill. -
value: thebyteelement.
-
-
fill
public static void fill(byte[] array, int start, int end, byte value) Fills the specified range in the array with the specified element.
Parameters
-
array: thebytearray to fill. -
start: the first index to fill. -
end: the last + 1 index to fill. -
value: thebyteelement.
Throws
-
IllegalArgumentException: ifstart > end. -
ArrayIndexOutOfBoundsException: ifstart array.length.
-
-
fill
public static void fill(short[] array, short value) Fills the specified array with the specified element.
Parameters
-
array: theshortarray to fill. -
value: theshortelement.
-
-
fill
public static void fill(short[] array, int start, int end, short value) Fills the specified range in the array with the specified element.
Parameters
-
array: theshortarray to fill. -
start: the first index to fill. -
end: the last + 1 index to fill. -
value: theshortelement.
Throws
-
IllegalArgumentException: ifstart > end. -
ArrayIndexOutOfBoundsException: ifstart array.length.
-
-
fill
public static void fill(char[] array, char value) Fills the specified array with the specified element.
Parameters
-
array: thechararray to fill. -
value: thecharelement.
-
-
fill
public static void fill(char[] array, int start, int end, char value) Fills the specified range in the array with the specified element.
Parameters
-
array: thechararray to fill. -
start: the first index to fill. -
end: the last + 1 index to fill. -
value: thecharelement.
Throws
-
IllegalArgumentException: ifstart > end. -
ArrayIndexOutOfBoundsException: ifstart array.length.
-
-
fill
public static void fill(int[] array, int value) Fills the specified array with the specified element.
Parameters
-
array: theintarray to fill. -
value: theintelement.
-
-
fill
public static void fill(int[] array, int start, int end, int value) Fills the specified range in the array with the specified element.
Parameters
-
array: theintarray to fill. -
start: the first index to fill. -
end: the last + 1 index to fill. -
value: theintelement.
Throws
-
IllegalArgumentException: ifstart > end. -
ArrayIndexOutOfBoundsException: ifstart array.length.
-
-
fill
public static void fill(long[] array, long value) Fills the specified array with the specified element.
Parameters
-
array: thelongarray to fill. -
value: thelongelement.
-
-
fill
public static void fill(long[] array, int start, int end, long value) Fills the specified range in the array with the specified element.
Parameters
-
array: thelongarray to fill. -
start: the first index to fill. -
end: the last + 1 index to fill. -
value: thelongelement.
Throws
-
IllegalArgumentException: ifstart > end. -
ArrayIndexOutOfBoundsException: ifstart array.length.
-
-
fill
public static void fill(float[] array, float value) Fills the specified array with the specified element.
Parameters
-
array: thefloatarray to fill. -
value: thefloatelement.
-
-
fill
public static void fill(float[] array, int start, int end, float value) Fills the specified range in the array with the specified element.
Parameters
-
array: thefloatarray to fill. -
start: the first index to fill. -
end: the last + 1 index to fill. -
value: thefloatelement.
Throws
-
IllegalArgumentException: ifstart > end. -
ArrayIndexOutOfBoundsException: ifstart array.length.
-
-
fill
public static void fill(double[] array, double value) Fills the specified array with the specified element.
Parameters
-
array: thedoublearray to fill. -
value: thedoubleelement.
-
-
fill
public static void fill(double[] array, int start, int end, double value) Fills the specified range in the array with the specified element.
Parameters
-
array: thedoublearray to fill. -
start: the first index to fill. -
end: the last + 1 index to fill. -
value: thedoubleelement.
Throws
-
IllegalArgumentException: ifstart > end. -
ArrayIndexOutOfBoundsException: ifstart array.length.
-
-
fill
public static void fill(boolean[] array, boolean value) Fills the specified array with the specified element.
Parameters
-
array: thebooleanarray to fill. -
value: thebooleanelement.
-
-
fill
public static void fill(boolean[] array, int start, int end, boolean value) Fills the specified range in the array with the specified element.
Parameters
-
array: thebooleanarray to fill. -
start: the first index to fill. -
end: the last + 1 index to fill. -
value: thebooleanelement.
Throws
-
IllegalArgumentException: ifstart > end. -
ArrayIndexOutOfBoundsException: ifstart array.length.
-
-
fill
-
fill
Fills the specified range in the array with the specified element.
Parameters
-
array: theObjectarray to fill. -
start: the first index to fill. -
end: the last + 1 index to fill. -
value: theObjectelement.
Throws
-
IllegalArgumentException: ifstart > end. -
ArrayIndexOutOfBoundsException: ifstart array.length.
-
-
hashCode
public static int hashCode(boolean[] array) Returns a hash code based on the contents of the given array. For any two
booleanarraysaandb, ifArrays.equals(a, b)returnstrue, it means that the return value ofArrays.hashCode(a)equalsArrays.hashCode(b).The value returned by this method is the same value as the
List#hashCode()} method which is invoked on aList} containing a sequence ofBoolean} instances representing the elements of array in the same order. If the array isnull, the return value is 0.Parameters
array: the array whose hash code to compute.
Returns
the hash code for
array. -
hashCode
public static int hashCode(int[] array) Returns a hash code based on the contents of the given array. For any two not-null
intarraysaandb, ifArrays.equals(a, b)returnstrue, it means that the return value ofArrays.hashCode(a)equalsArrays.hashCode(b).The value returned by this method is the same value as the
List#hashCode()} method which is invoked on aList} containing a sequence ofInteger} instances representing the elements of array in the same order. If the array isnull, the return value is 0.Parameters
array: the array whose hash code to compute.
Returns
the hash code for
array. -
hashCode
public static int hashCode(short[] array) Returns a hash code based on the contents of the given array. For any two
shortarraysaandb, ifArrays.equals(a, b)returnstrue, it means that the return value ofArrays.hashCode(a)equalsArrays.hashCode(b).The value returned by this method is the same value as the
List#hashCode()} method which is invoked on aList} containing a sequence ofShort} instances representing the elements of array in the same order. If the array isnull, the return value is 0.Parameters
array: the array whose hash code to compute.
Returns
the hash code for
array. -
hashCode
public static int hashCode(char[] array) Returns a hash code based on the contents of the given array. For any two
chararraysaandb, ifArrays.equals(a, b)returnstrue, it means that the return value ofArrays.hashCode(a)equalsArrays.hashCode(b).The value returned by this method is the same value as the
List#hashCode()} method which is invoked on aList} containing a sequence ofCharacter} instances representing the elements of array in the same order. If the array isnull, the return value is 0.Parameters
array: the array whose hash code to compute.
Returns
the hash code for
array. -
hashCode
public static int hashCode(byte[] array) Returns a hash code based on the contents of the given array. For any two
bytearraysaandb, ifArrays.equals(a, b)returnstrue, it means that the return value ofArrays.hashCode(a)equalsArrays.hashCode(b).The value returned by this method is the same value as the
List#hashCode()} method which is invoked on aList} containing a sequence ofByte} instances representing the elements of array in the same order. If the array isnull, the return value is 0.Parameters
array: the array whose hash code to compute.
Returns
the hash code for
array. -
hashCode
public static int hashCode(long[] array) Returns a hash code based on the contents of the given array. For any two
longarraysaandb, ifArrays.equals(a, b)returnstrue, it means that the return value ofArrays.hashCode(a)equalsArrays.hashCode(b).The value returned by this method is the same value as the
List#hashCode()} method which is invoked on aList} containing a sequence ofLong} instances representing the elements of array in the same order. If the array isnull, the return value is 0.Parameters
array: the array whose hash code to compute.
Returns
the hash code for
array. -
hashCode
public static int hashCode(float[] array) Returns a hash code based on the contents of the given array. For any two
floatarraysaandb, ifArrays.equals(a, b)returnstrue, it means that the return value ofArrays.hashCode(a)equalsArrays.hashCode(b).The value returned by this method is the same value as the
List#hashCode()} method which is invoked on aList} containing a sequence ofFloat} instances representing the elements of array in the same order. If the array isnull, the return value is 0.Parameters
array: the array whose hash code to compute.
Returns
the hash code for
array. -
hashCode
public static int hashCode(double[] array) Returns a hash code based on the contents of the given array. For any two
doublearraysaandb, ifArrays.equals(a, b)returnstrue, it means that the return value ofArrays.hashCode(a)equalsArrays.hashCode(b).The value returned by this method is the same value as the
List#hashCode()} method which is invoked on aList} containing a sequence ofDouble} instances representing the elements of array in the same order. If the array isnull, the return value is 0.Parameters
array: the array whose hash code to compute.
Returns
the hash code for
array. -
hashCode
Returns a hash code based on the contents of the given array. If the array contains other arrays as its elements, the hash code is based on their identities not their contents. So it is acceptable to invoke this method on an array that contains itself as an element, either directly or indirectly.
For any two arrays
aandb, ifArrays.equals(a, b)returnstrue, it means that the return value ofArrays.hashCode(a)equalsArrays.hashCode(b).The value returned by this method is the same value as the method Arrays.asList(array).hashCode(). If the array is
null, the return value is 0.Parameters
array: the array whose hash code to compute.
Returns
the hash code for
array. -
deepHashCode
Returns a hash code based on the "deep contents" of the given array. If the array contains other arrays as its elements, the hash code is based on their contents not their identities. So it is not acceptable to invoke this method on an array that contains itself as an element, either directly or indirectly.
For any two arrays
aandb, ifArrays.deepEquals(a, b)returnstrue, it means that the return value ofArrays.deepHashCode(a)equalsArrays.deepHashCode(b).The computation of the value returned by this method is similar to that of the value returned by
List#hashCode()} invoked on aList} containing a sequence of instances representing the elements of array in the same order. The difference is: If an element e of array is itself an array, its hash code is computed by calling the appropriate overloading ofArrays.hashCode(e)if e is an array of a primitive type, or by callingArrays.deepHashCode(e)recursively if e is an array of a reference type. The value returned by this method is the same value as the methodArrays.asList(array).hashCode(). If the array isnull, the return value is 0.Parameters
array: the array whose hash code to compute.
Returns
the hash code for
array. -
equals
public static boolean equals(byte[] array1, byte[] array2) Compares the two arrays.
Parameters
-
array1: the firstbytearray. -
array2: the secondbytearray.
Returns
- Returns:
trueif both arrays arenullor if the arrays have the same length and the elements at each index in the two arrays are equal,falseotherwise.
-
-
equals
public static boolean equals(short[] array1, short[] array2) Compares the two arrays.
Parameters
-
array1: the firstshortarray. -
array2: the secondshortarray.
Returns
- Returns:
trueif both arrays arenullor if the arrays have the same length and the elements at each index in the two arrays are equal,falseotherwise.
-
-
equals
public static boolean equals(char[] array1, char[] array2) Compares the two arrays.
Parameters
-
array1: the firstchararray. -
array2: the secondchararray.
Returns
- Returns:
trueif both arrays arenullor if the arrays have the same length and the elements at each index in the two arrays are equal,falseotherwise.
-
-
equals
public static boolean equals(int[] array1, int[] array2) Compares the two arrays.
Parameters
-
array1: the firstintarray. -
array2: the secondintarray.
Returns
- Returns:
trueif both arrays arenullor if the arrays have the same length and the elements at each index in the two arrays are equal,falseotherwise.
-
-
equals
public static boolean equals(long[] array1, long[] array2) Compares the two arrays.
Parameters
-
array1: the firstlongarray. -
array2: the secondlongarray.
Returns
- Returns:
trueif both arrays arenullor if the arrays have the same length and the elements at each index in the two arrays are equal,falseotherwise.
-
-
equals
public static boolean equals(float[] array1, float[] array2) Compares the two arrays. The values are compared in the same manner as
Float.equals().Parameters
-
array1: the firstfloatarray. -
array2: the secondfloatarray.
Returns
- Returns:
trueif both arrays arenullor if the arrays have the same length and the elements at each index in the two arrays are equal,falseotherwise.See also
- Float#equals(Object)
-
-
equals
public static boolean equals(double[] array1, double[] array2) Compares the two arrays. The values are compared in the same manner as
Double.equals().Parameters
-
array1: the firstdoublearray. -
array2: the seconddoublearray.
Returns
- Returns:
trueif both arrays arenullor if the arrays have the same length and the elements at each index in the two arrays are equal,falseotherwise.See also
- Double#equals(Object)
-
-
equals
public static boolean equals(boolean[] array1, boolean[] array2) Compares the two arrays.
Parameters
-
array1: the firstbooleanarray. -
array2: the secondbooleanarray.
Returns
- Returns:
trueif both arrays arenullor if the arrays have the same length and the elements at each index in the two arrays are equal,falseotherwise.
-
-
equals
Compares the two arrays.
Parameters
-
array1: the firstObjectarray. -
array2: the secondObjectarray.
Returns
- Returns:
trueif both arrays arenullor if the arrays have the same length and the elements at each index in the two arrays are equal according toequals(),falseotherwise.
-
-
deepEquals
Returns
trueif the two given arrays are deeply equal to one another. Unlike the methodequals(Object[] array1, Object[] array2), this method is appropriate for use for nested arrays of arbitrary depth.Two array references are considered deeply equal if they are both
null, or if they refer to arrays that have the same length and the elements at each index in the two arrays are equal.Two
nullelementselement1andelement2are possibly deeply equal if any of the following conditions satisfied:element1andelement2are both arrays of object reference types, andArrays.deepEquals(element1, element2)would returntrue.element1andelement2are arrays of the same primitive type, and the appropriate overloading ofArrays.equals(element1, element2)would returntrue.element1 == element2element1.equals(element2)would returntrue.Note that this definition permits
nullelements at any depth.If either of the given arrays contain themselves as elements, the behavior of this method is uncertain.
Parameters
-
array1: the firstObjectarray. -
array2: the secondObjectarray.
Returns
- Returns:
trueif both arrays arenullor if the arrays have the same length and the elements at each index in the two arrays are equal according toequals(),falseotherwise.
-
-
sort
public static void sort(byte[] array) Sorts the specified array in ascending numerical order.
Parameters
array: thebytearray to be sorted.
-
sort
public static void sort(byte[] array, int start, int end) Sorts the specified range in the array in ascending numerical order.
Parameters
-
array: thebytearray to be sorted. -
start: the start index to sort. -
end: the last + 1 index to sort.
Throws
-
IllegalArgumentException: ifstart > end. -
ArrayIndexOutOfBoundsException: ifstart array.length.
-
-
sort
public static void sort(char[] array) Sorts the specified array in ascending numerical order.
Parameters
array: thechararray to be sorted.
-
sort
public static void sort(char[] array, int start, int end) Sorts the specified range in the array in ascending numerical order.
Parameters
-
array: thechararray to be sorted. -
start: the start index to sort. -
end: the last + 1 index to sort.
Throws
-
IllegalArgumentException: ifstart > end. -
ArrayIndexOutOfBoundsException: ifstart array.length.
-
-
sort
public static void sort(double[] array) Sorts the specified array in ascending numerical order.
Parameters
array: thedoublearray to be sorted.
See also
- #sort(double[], int, int)
-
sort
public static void sort(double[] array, int start, int end) Sorts the specified range in the array in ascending numerical order. The values are sorted according to the order imposed by
Double.compareTo().Parameters
-
array: thedoublearray to be sorted. -
start: the start index to sort. -
end: the last + 1 index to sort.
Throws
-
IllegalArgumentException: ifstart > end. -
ArrayIndexOutOfBoundsException: ifstart array.length.
See also
- Double#compareTo(Double)
-
-
sort
public static void sort(float[] array) Sorts the specified array in ascending numerical order.
Parameters
array: thefloatarray to be sorted.
See also
- #sort(float[], int, int)
-
sort
public static void sort(float[] array, int start, int end) Sorts the specified range in the array in ascending numerical order. The values are sorted according to the order imposed by
Float.compareTo().Parameters
-
array: thefloatarray to be sorted. -
start: the start index to sort. -
end: the last + 1 index to sort.
Throws
-
IllegalArgumentException: ifstart > end. -
ArrayIndexOutOfBoundsException: ifstart array.length.
See also
- Float#compareTo(Float)
-
-
sort
public static void sort(int[] array) Sorts the specified array in ascending numerical order.
Parameters
array: theintarray to be sorted.
-
sort
public static void sort(int[] array, int start, int end) Sorts the specified range in the array in ascending numerical order.
Parameters
-
array: theintarray to be sorted. -
start: the start index to sort. -
end: the last + 1 index to sort.
Throws
-
IllegalArgumentException: ifstart > end. -
ArrayIndexOutOfBoundsException: ifstart array.length.
-
-
sort
public static void sort(long[] array) Sorts the specified array in ascending numerical order.
Parameters
array: thelongarray to be sorted.
-
sort
public static void sort(long[] array, int start, int end) Sorts the specified range in the array in ascending numerical order.
Parameters
-
array: thelongarray to be sorted. -
start: the start index to sort. -
end: the last + 1 index to sort.
Throws
-
IllegalArgumentException: ifstart > end. -
ArrayIndexOutOfBoundsException: ifstart array.length.
-
-
sort
Sorts the specified array in ascending natural order.
Parameters
array: theObjectarray to be sorted.
Throws
ClassCastException: @throws ClassCastException if an element in the array does not implementComparableor if some elements cannot be compared to each other.
See also
- #sort(Object[], int, int)
-
sort
Sorts the specified range in the array in ascending natural order. All elements must implement the
Comparableinterface and must be comparable to each other without aClassCastExceptionbeing thrown.Parameters
-
array: theObjectarray to be sorted. -
start: the start index to sort. -
end: the last + 1 index to sort.
Throws
-
ClassCastException: @throws ClassCastException if an element in the array does not implementComparableor some elements cannot be compared to each other. -
IllegalArgumentException: ifstart > end. -
ArrayIndexOutOfBoundsException: ifstart array.length.
-
-
sort
Sorts the specified range in the array using the specified
Comparator. All elements must be comparable to each other without aClassCastExceptionbeing thrown.Parameters
-
array: theObjectarray to be sorted. -
start: the start index to sort. -
end: the last + 1 index to sort. -
comparator: theComparator.
Throws
-
ClassCastException: @throws ClassCastException if elements in the array cannot be compared to each other using theComparator. -
IllegalArgumentException: ifstart > end. -
ArrayIndexOutOfBoundsException: ifstart array.length.
-
-
sort
Sorts the specified array using the specified
Comparator. All elements must be comparable to each other without aClassCastExceptionbeing thrown.Parameters
-
array: theObjectarray to be sorted. -
comparator: theComparator.
Throws
ClassCastException: @throws ClassCastException if elements in the array cannot be compared to each other using theComparator.
-
-
sort
public static void sort(short[] array) Sorts the specified array in ascending numerical order.
Parameters
array: theshortarray to be sorted.
-
sort
public static void sort(short[] array, int start, int end) Sorts the specified range in the array in ascending numerical order.
Parameters
-
array: theshortarray to be sorted. -
start: the start index to sort. -
end: the last + 1 index to sort.
Throws
-
IllegalArgumentException: ifstart > end. -
ArrayIndexOutOfBoundsException: ifstart array.length.
-
-
toString
Creates a
Stringrepresentation of theboolean[]passed. The result is surrounded by brackets ("[]"), each element is converted to aStringvia theString#valueOf(boolean)and separated by", ". If the array isnull, then"null"is returned.Parameters
array: thebooleanarray to convert.
Returns
the
Stringrepresentation ofarray.Since
1.5
-
toString
Creates a
Stringrepresentation of thebyte[]passed. The result is surrounded by brackets ("[]"), each element is converted to aStringvia theString#valueOf(int)and separated by", ". If the array isnull, then"null"is returned.Parameters
array: thebytearray to convert.
Returns
the
Stringrepresentation ofarray.Since
1.5
-
toString
Creates a
Stringrepresentation of thechar[]passed. The result is surrounded by brackets ("[]"), each element is converted to aStringvia theString#valueOf(char)and separated by", ". If the array isnull, then"null"is returned.Parameters
array: thechararray to convert.
Returns
the
Stringrepresentation ofarray.Since
1.5
-
toString
Creates a
Stringrepresentation of thedouble[]passed. The result is surrounded by brackets ("[]"), each element is converted to aStringvia theString#valueOf(double)and separated by", ". If the array isnull, then"null"is returned.Parameters
array: thedoublearray to convert.
Returns
the
Stringrepresentation ofarray.Since
1.5
-
toString
Creates a
Stringrepresentation of thefloat[]passed. The result is surrounded by brackets ("[]"), each element is converted to aStringvia theString#valueOf(float)and separated by", ". If the array isnull, then"null"is returned.Parameters
array: thefloatarray to convert.
Returns
the
Stringrepresentation ofarray.Since
1.5
-
toString
Creates a
Stringrepresentation of theint[]passed. The result is surrounded by brackets ("[]"), each element is converted to aStringvia theString#valueOf(int)and separated by", ". If the array isnull, then"null"is returned.Parameters
array: theintarray to convert.
Returns
the
Stringrepresentation ofarray.Since
1.5
-
toString
Creates a
Stringrepresentation of thelong[]passed. The result is surrounded by brackets ("[]"), each element is converted to aStringvia theString#valueOf(long)and separated by", ". If the array isnull, then"null"is returned.Parameters
array: thelongarray to convert.
Returns
the
Stringrepresentation ofarray.Since
1.5
-
toString
Creates a
Stringrepresentation of theshort[]passed. The result is surrounded by brackets ("[]"), each element is converted to aStringvia theString#valueOf(int)and separated by", ". If the array isnull, then"null"is returned.Parameters
array: theshortarray to convert.
Returns
the
Stringrepresentation ofarray.Since
1.5
-
toString
Creates a
Stringrepresentation of theObject[]passed. The result is surrounded by brackets ("[]"), each element is converted to aStringvia theString#valueOf(Object)and separated by", ". If the array isnull, then"null"is returned.Parameters
array: theObjectarray to convert.
Returns
the
Stringrepresentation ofarray.Since
1.5
-
deepToString
Creates a "deep"
Stringrepresentation of theObject[]passed, such that if the array contains other arrays, theStringrepresentation of those arrays is generated as well.If any of the elements are primitive arrays, the generation is delegated to the other
toStringmethods in this class. If any element contains a reference to the original array, then it will be represented as"[...]". If an element is anObject[], then its representation is generated by a recursive call to this method. All other elements are converted via theString#valueOf(Object)method.Parameters
array: theObjectarray to convert.
Returns
the
Stringrepresentation ofarray.Since
1.5
-
copyOfRange
public static boolean[] copyOfRange(boolean[] original, int start, int end) Copies elements in original array to a new array, from index start(inclusive) to end(exclusive). The first element (if any) in the new array is original[
from], and other elements in the new array are in the original order. The padding value whose index is bigger than or equal to original.length - start is false.Parameters
-
original: the original array -
start: the start index, inclusive -
end: the end index, exclusive, may bigger than length of the array
Returns
the new copied array
Throws
-
ArrayIndexOutOfBoundsException: if start is smaller than 0 or bigger than original.length -
IllegalArgumentException: if start is bigger than end -
NullPointerException: if original is null
Since
1.6
-
-
copyOfRange
public static byte[] copyOfRange(byte[] original, int start, int end) Copies elements in original array to a new array, from index start(inclusive) to end(exclusive). The first element (if any) in the new array is original[
from], and other elements in the new array are in the original order. The padding value whose index is bigger than or equal to original.length - start is (byte)0.Parameters
-
original: the original array -
start: the start index, inclusive -
end: the end index, exclusive, may bigger than length of the array
Returns
the new copied array
Throws
-
ArrayIndexOutOfBoundsException: if start is smaller than 0 or bigger than original.length -
IllegalArgumentException: if start is bigger than end -
NullPointerException: if original is null
Since
1.6
-
-
copyOfRange
public static char[] copyOfRange(char[] original, int start, int end) Copies elements in original array to a new array, from index start(inclusive) to end(exclusive). The first element (if any) in the new array is original[
from], and other elements in the new array are in the original order. The padding value whose index is bigger than or equal to original.length - start is '\u000'.Parameters
-
original: the original array -
start: the start index, inclusive -
end: the end index, exclusive, may bigger than length of the array
Returns
the new copied array
Throws
-
ArrayIndexOutOfBoundsException: if start is smaller than 0 or bigger than original.length -
IllegalArgumentException: if start is bigger than end -
NullPointerException: if original is null
Since
1.6
-
-
copyOfRange
public static double[] copyOfRange(double[] original, int start, int end) Copies elements in original array to a new array, from index start(inclusive) to end(exclusive). The first element (if any) in the new array is original[
from], and other elements in the new array are in the original order. The padding value whose index is bigger than or equal to original.length - start is 0d.Parameters
-
original: the original array -
start: the start index, inclusive -
end: the end index, exclusive, may bigger than length of the array
Returns
the new copied array
Throws
-
ArrayIndexOutOfBoundsException: if start is smaller than 0 or bigger than original.length -
IllegalArgumentException: if start is bigger than end -
NullPointerException: if original is null
Since
1.6
-
-
copyOfRange
public static float[] copyOfRange(float[] original, int start, int end) Copies elements in original array to a new array, from index start(inclusive) to end(exclusive). The first element (if any) in the new array is original[
from], and other elements in the new array are in the original order. The padding value whose index is bigger than or equal to original.length - start is 0f.Parameters
-
original: the original array -
start: the start index, inclusive -
end: the end index, exclusive, may bigger than length of the array
Returns
the new copied array
Throws
-
ArrayIndexOutOfBoundsException: if start is smaller than 0 or bigger than original.length -
IllegalArgumentException: if start is bigger than end -
NullPointerException: if original is null
Since
1.6
-
-
copyOfRange
public static int[] copyOfRange(int[] original, int start, int end) Copies elements in original array to a new array, from index start(inclusive) to end(exclusive). The first element (if any) in the new array is original[
from], and other elements in the new array are in the original order. The padding value whose index is bigger than or equal to original.length - start is 0.Parameters
-
original: the original array -
start: the start index, inclusive -
end: the end index, exclusive, may bigger than length of the array
Returns
the new copied array
Throws
-
ArrayIndexOutOfBoundsException: if start is smaller than 0 or bigger than original.length -
IllegalArgumentException: if start is bigger than end -
NullPointerException: if original is null
Since
1.6
-
-
copyOfRange
public static long[] copyOfRange(long[] original, int start, int end) Copies elements in original array to a new array, from index start(inclusive) to end(exclusive). The first element (if any) in the new array is original[
from], and other elements in the new array are in the original order. The padding value whose index is bigger than or equal to original.length - start is 0L.Parameters
-
original: the original array -
start: the start index, inclusive -
end: the end index, exclusive, may bigger than length of the array
Returns
the new copied array
Throws
-
ArrayIndexOutOfBoundsException: if start is smaller than 0 or bigger than original.length -
IllegalArgumentException: if start is bigger than end -
NullPointerException: if original is null
Since
1.6
-
-
copyOfRange
public static short[] copyOfRange(short[] original, int start, int end) Copies elements in original array to a new array, from index start(inclusive) to end(exclusive). The first element (if any) in the new array is original[
from], and other elements in the new array are in the original order. The padding value whose index is bigger than or equal to original.length - start is (short)0.Parameters
-
original: the original array -
start: the start index, inclusive -
end: the end index, exclusive, may bigger than length of the array
Returns
the new copied array
Throws
-
ArrayIndexOutOfBoundsException: if start is smaller than 0 or bigger than original.length -
IllegalArgumentException: if start is bigger than end -
NullPointerException: if original is null
Since
1.6
-
-
copyOfRange
-
copyOfRange
public static <T> T[] copyOfRange(T[] original, int from, int to) -
copyOf
-
copyOf
public static <T> T[] copyOf(T[] original, int newLength) -
copyOf
public static boolean[] copyOf(boolean[] original, int newlen) -
copyOf
public static char[] copyOf(char[] original, int newlen) -
copyOf
public static double[] copyOf(double[] original, int newlen) -
copyOf
public static float[] copyOf(float[] original, int newlen) -
copyOf
public static long[] copyOf(long[] original, int newlen) -
copyOf
public static int[] copyOf(int[] original, int newlen) -
copyOf
public static byte[] copyOf(byte[] original, int newlen) -
copyOf
public static short[] copyOf(short[] original, int len)
-