java.util

Class Arrays


public class Arrays
extends Object

This class contains various static utility methods performing operations on arrays, and a method to provide a List "view" of an array to facilitate using arrays with Collection-based APIs. All methods throw a NullPointerException if the parameter array is null.

Implementations may use their own algorithms, but must obey the general properties; for example, the sort must be stable and n*log(n) complexity. Sun's implementation of sort, and therefore ours, is a tuned quicksort, adapted from Jon L. Bentley and M. Douglas McIlroy's "Engineering a Sort Function", Software-Practice and Experience, Vol. 23(11) P. 1249-1265 (November 1993). This algorithm offers n*log(n) performance on many data sets that cause other quicksorts to degrade to quadratic performance.

Since:
1.2
See Also:
Comparable, Comparator

Method Summary

static
List asList(T... a)
Returns a list "view" of the specified array.
static
T[] copyOf(T[] original, int newLength)
Returns a copy of the supplied array, truncating or padding as necessary with null to obtain the specified length.
static
T[] copyOf(U[] original, int newLength, >[] newType)
Returns a copy of the supplied array, truncating or padding as necessary with null to obtain the specified length.
static
T[] copyOfRange(T[] original, int from, int to)
Copies the specified range of the supplied array to a new array, padding as necessary with null if to is greater than the length of the original array.
static
T[] copyOfRange(U[] original, int from, int to, >[] newType)
Copies the specified range of the supplied array to a new array, padding as necessary with null if to is greater than the length of the original array.
static int
binarySearch(byte[] a, byte key)
Perform a binary search of a byte array for a key.
static int
binarySearch(byte[] a, int low, int hi, byte key)
Perform a binary search of a range of a byte array for a key.
static int
binarySearch(char[] a, char key)
Perform a binary search of a char array for a key.
static int
binarySearch(char[] a, int low, int hi, char key)
Perform a binary search of a range of a char array for a key.
static int
binarySearch(double[] a, double key)
Perform a binary search of a double array for a key.
static int
binarySearch(double[] a, int low, int hi, double key)
Perform a binary search of a range of a double array for a key.
static int
binarySearch(float[] a, float key)
Perform a binary search of a float array for a key.
static int
binarySearch(float[] a, int low, int hi, float key)
Perform a binary search of a range of a float array for a key.
static int
binarySearch(int[] a, int key)
Perform a binary search of an int array for a key.
static int
binarySearch(int[] a, int low, int hi, int key)
Perform a binary search of a range of an integer array for a key.
static int
binarySearch(Object[] a, int low, int hi, Object key)
Perform a binary search of a range of an Object array for a key.
static int
binarySearch(Object[] a, Object key)
Perform a binary search of an Object array for a key, using the natural ordering of the elements.
static int
binarySearch(long[] a, int low, int hi, long key)
Perform a binary search of a range of a long array for a key.
static int
binarySearch(long[] a, long key)
Perform a binary search of a long array for a key.
static int
binarySearch(short[] a, int low, int hi, short key)
Perform a binary search of a range of a short array for a key.
static int
binarySearch(short[] a, short key)
Perform a binary search of a short array for a key.
static boolean[]
copyOf(boolean[] original, int newLength)
Returns a copy of the supplied array, truncating or padding as necessary with false to obtain the specified length.
static byte[]
copyOf(byte[] original, int newLength)
Returns a copy of the supplied array, truncating or padding as necessary with (byte)0 to obtain the specified length.
static char[]
copyOf(char[] original, int newLength)
Returns a copy of the supplied array, truncating or padding as necessary with '\0' to obtain the specified length.
static double[]
copyOf(double[] original, int newLength)
Returns a copy of the supplied array, truncating or padding as necessary with 0d to obtain the specified length.
static float[]
copyOf(float[] original, int newLength)
Returns a copy of the supplied array, truncating or padding as necessary with 0f to obtain the specified length.
static int[]
copyOf(int[] original, int newLength)
Returns a copy of the supplied array, truncating or padding as necessary with 0 to obtain the specified length.
static long[]
copyOf(long[] original, int newLength)
Returns a copy of the supplied array, truncating or padding as necessary with 0L to obtain the specified length.
static short[]
copyOf(short[] original, int newLength)
Returns a copy of the supplied array, truncating or padding as necessary with (short)0 to obtain the specified length.
static boolean[]
copyOfRange(boolean[] original, int from, int to)
Copies the specified range of the supplied array to a new array, padding as necessary with false if to is greater than the length of the original array.
static byte[]
copyOfRange(byte[] original, int from, int to)
Copies the specified range of the supplied array to a new array, padding as necessary with (byte)0 if to is greater than the length of the original array.
static char[]
copyOfRange(char[] original, int from, int to)
Copies the specified range of the supplied array to a new array, padding as necessary with '\0' if to is greater than the length of the original array.
static double[]
copyOfRange(double[] original, int from, int to)
Copies the specified range of the supplied array to a new array, padding as necessary with 0d if to is greater than the length of the original array.
static float[]
copyOfRange(float[] original, int from, int to)
Copies the specified range of the supplied array to a new array, padding as necessary with 0f if to is greater than the length of the original array.
static int[]
copyOfRange(int[] original, int from, int to)
Copies the specified range of the supplied array to a new array, padding as necessary with 0 if to is greater than the length of the original array.
static long[]
copyOfRange(long[] original, int from, int to)
Copies the specified range of the supplied array to a new array, padding as necessary with 0L if to is greater than the length of the original array.
static short[]
copyOfRange(short[] original, int from, int to)
Copies the specified range of the supplied array to a new array, padding as necessary with (short)0 if to is greater than the length of the original array.
static boolean
deepEquals(Object[] v1, Object[] v2)
static int
deepHashCode(Object[] v)
static String
deepToString(Object[] v)
static boolean
equals(boolean[] a1, boolean[] a2)
Compare two boolean arrays for equality.
static boolean
equals(byte[] a1, byte[] a2)
Compare two byte arrays for equality.
static boolean
equals(char[] a1, char[] a2)
Compare two char arrays for equality.
static boolean
equals(double[] a1, double[] a2)
Compare two double arrays for equality.
static boolean
equals(float[] a1, float[] a2)
Compare two float arrays for equality.
static boolean
equals(int[] a1, int[] a2)
Compare two int arrays for equality.
static boolean
equals(Object[] a1, Object[] a2)
Compare two Object arrays for equality.
static boolean
equals(long[] a1, long[] a2)
Compare two long arrays for equality.
static boolean
equals(short[] a1, short[] a2)
Compare two short arrays for equality.
static void
fill(boolean[] a, boolean val)
Fill an array with a boolean value.
static void
fill(boolean[] a, int fromIndex, int toIndex, boolean val)
Fill a range of an array with a boolean value.
static void
fill(byte[] a, byte val)
Fill an array with a byte value.
static void
fill(byte[] a, int fromIndex, int toIndex, byte val)
Fill a range of an array with a byte value.
static void
fill(char[] a, char val)
Fill an array with a char value.
static void
fill(char[] a, int fromIndex, int toIndex, char val)
Fill a range of an array with a char value.
static void
fill(double[] a, double val)
Fill an array with a double value.
static void
fill(double[] a, int fromIndex, int toIndex, double val)
Fill a range of an array with a double value.
static void
fill(float[] a, float val)
Fill an array with a float value.
static void
fill(float[] a, int fromIndex, int toIndex, float val)
Fill a range of an array with a float value.
static void
fill(int[] a, int val)
Fill an array with an int value.
static void
fill(int[] a, int fromIndex, int toIndex, int val)
Fill a range of an array with an int value.
static void
fill(Object[] a, int fromIndex, int toIndex, Object val)
Fill a range of an array with an Object value.
static void
fill(Object[] a, Object val)
Fill an array with an Object value.
static void
fill(long[] a, int fromIndex, int toIndex, long val)
Fill a range of an array with a long value.
static void
fill(long[] a, long val)
Fill an array with a long value.
static void
fill(short[] a, int fromIndex, int toIndex, short val)
Fill a range of an array with a short value.
static void
fill(short[] a, short val)
Fill an array with a short value.
static int
hashCode(boolean[] v)
Returns the hashcode of an array of booleans.
static int
hashCode(byte[] v)
Returns the hashcode of an array of bytes.
static int
hashCode(char[] v)
Returns the hashcode of an array of characters.
static int
hashCode(double[] v)
Returns the hashcode of an array of doubles.
static int
hashCode(float[] v)
Returns the hashcode of an array of floats.
static int
hashCode(int[] v)
Returns the hashcode of an array of integer numbers.
static int
hashCode(Object[] v)
Returns the hashcode of an array of objects.
static int
hashCode(long[] v)
Returns the hashcode of an array of long numbers.
static int
hashCode(short[] v)
Returns the hashcode of an array of short numbers.
static
int binarySearch(T[] a, T key, T> c)
Perform a binary search of an Object array for a key, using a supplied Comparator.
static
int binarySearch(T[] a, int low, int hi, T key, T> c)
Perform a binary search of a range of an Object array for a key using a Comparator.
static void
sort(byte[] a)
Performs a stable sort on the elements, arranging them according to their natural order.
static void
sort(byte[] a, int fromIndex, int toIndex)
Performs a stable sort on the elements, arranging them according to their natural order.
static void
sort(char[] a)
Performs a stable sort on the elements, arranging them according to their natural order.
static void
sort(char[] a, int fromIndex, int toIndex)
Performs a stable sort on the elements, arranging them according to their natural order.
static void
sort(double[] a)
Performs a stable sort on the elements, arranging them according to their natural order.
static void
sort(double[] a, int fromIndex, int toIndex)
Performs a stable sort on the elements, arranging them according to their natural order.
static void
sort(float[] a)
Performs a stable sort on the elements, arranging them according to their natural order.
static void
sort(float[] a, int fromIndex, int toIndex)
Performs a stable sort on the elements, arranging them according to their natural order.
static void
sort(int[] a)
Performs a stable sort on the elements, arranging them according to their natural order.
static void
sort(int[] a, int fromIndex, int toIndex)
Performs a stable sort on the elements, arranging them according to their natural order.
static void
sort(Object[] a)
Sort an array of Objects according to their natural ordering.
static void
sort(Object[] a, int fromIndex, int toIndex)
Sort an array of Objects according to their natural ordering.
static void
sort(long[] a)
Performs a stable sort on the elements, arranging them according to their natural order.
static void
sort(long[] a, int fromIndex, int toIndex)
Performs a stable sort on the elements, arranging them according to their natural order.
static void
sort(short[] a)
Performs a stable sort on the elements, arranging them according to their natural order.
static void
sort(short[] a, int fromIndex, int toIndex)
Performs a stable sort on the elements, arranging them according to their natural order.
static String
toString(boolean[] v)
Returns a String representation of the argument array.
static String
toString(byte[] v)
Returns a String representation of the argument array.
static String
toString(char[] v)
Returns a String representation of the argument array.
static String
toString(double[] v)
Returns a String representation of the argument array.
static String
toString(float[] v)
Returns a String representation of the argument array.
static String
toString(int[] v)
Returns a String representation of the argument array.
static String
toString(Object[] v)
Returns a String representation of the argument array.
static String
toString(long[] v)
Returns a String representation of the argument array.
static String
toString(short[] v)
Returns a String representation of the argument array.
static
void sort(T[] a, T> c)
Sort an array of Objects according to a Comparator.
static
void sort(T[] a, int fromIndex, int toIndex, T> c)
Sort an array of Objects according to a Comparator.

Methods inherited from class java.lang.Object

clone, equals, extends Object> getClass, finalize, hashCode, notify, notifyAll, toString, wait, wait, wait

Method Details

List asList

public static  List asList(T... a)
Returns a list "view" of the specified array. This method is intended to make it easy to use the Collections API with existing array-based APIs and programs. Changes in the list or the array show up in both places. The list does not support element addition or removal, but does permit value modification. The returned list implements both Serializable and RandomAccess.
Parameters:
a - the array to return a view of (null not permitted)
Returns:
a fixed-size list, changes to which "write through" to the array
Throws:
NullPointerException - if a is null.
See Also:
Serializable, RandomAccess, Arrays.ArrayList

T[] copyOf

public static  T[] copyOf(T[] original,
                             int newLength)
Returns a copy of the supplied array, truncating or padding as necessary with null to obtain the specified length. Indices that are valid for both arrays will return the same value. Indices that only exist in the returned array (due to the new length being greater than the original length) will return null. This is equivalent to calling copyOfRange(original, 0, newLength).
Parameters:
original - the original array to be copied.
newLength - the length of the returned array.
Returns:
a copy of the original array, truncated or padded with null to obtain the required length.
Throws:
NegativeArraySizeException - if newLength is negative.
NullPointerException - if original is null.
Since:
1.6
See Also:
copyOfRange(T[],int,int)

T[] copyOf

public static  T[] copyOf(U[] original,
                               int newLength,
                               >[] newType)
Returns a copy of the supplied array, truncating or padding as necessary with null to obtain the specified length. Indices that are valid for both arrays will return the same value. Indices that only exist in the returned array (due to the new length being greater than the original length) will return null. This is equivalent to calling copyOfRange(original, 0, newLength, newType). The returned array will be of the specified type, newType.
Parameters:
original - the original array to be copied.
newLength - the length of the returned array.
newType - the type of the returned array.
Returns:
a copy of the original array, truncated or padded with null to obtain the required length.
Throws:
NegativeArraySizeException - if newLength is negative.
NullPointerException - if original is null.
Since:
1.6
See Also:
copyOfRange(U[],int,int,Class)

T[] copyOfRange

public static  T[] copyOfRange(T[] original,
                                  int from,
                                  int to)
Copies the specified range of the supplied array to a new array, padding as necessary with null if to is greater than the length of the original array. from must be in the range zero to original.length and can not be greater than to. The initial element of the returned array will be equal to original[from], except where from is equal to to (where a zero-length array will be returned) or from is equal to original.length (where an array padded with null will be returned). The returned array is always of length to - from.
Parameters:
original - the array from which to copy.
from - the initial index of the range, inclusive.
to - the final index of the range, exclusive.
Returns:
a copy of the specified range, with padding to obtain the required length.
Throws:
ArrayIndexOutOfBoundsException - if from <320 or from > original.length
IllegalArgumentException - if from > to
NullPointerException - if original is null.
Since:
1.6
See Also:
copyOf(T[],int)

T[] copyOfRange

public static  T[] copyOfRange(U[] original,
                                    int from,
                                    int to,
                                    >[] newType)
Copies the specified range of the supplied array to a new array, padding as necessary with null if to is greater than the length of the original array. from must be in the range zero to original.length and can not be greater than to. The initial element of the returned array will be equal to original[from], except where from is equal to to (where a zero-length array will be returned) or from is equal to original.length (where an array padded with null will be returned). The returned array is always of length to - from and will be of the specified type, newType.
Parameters:
original - the array from which to copy.
from - the initial index of the range, inclusive.
to - the final index of the range, exclusive.
newType - the type of the returned array.
Returns:
a copy of the specified range, with padding to obtain the required length.
Throws:
ArrayIndexOutOfBoundsException - if from <320 or from > original.length
IllegalArgumentException - if from > to
NullPointerException - if original is null.
Since:
1.6
See Also:
copyOf(T[],int)

binarySearch

public static int binarySearch(byte[] a,
                               byte key)
Perform a binary search of a byte array for a key. The array must be sorted (as by the sort() method) - if it is not, the behaviour of this method is undefined, and may be an infinite loop. If the array contains the key more than once, any one of them may be found. Note: although the specification allows for an infinite loop if the array is unsorted, it will not happen in this implementation.
Parameters:
a - the array to search (must be sorted)
key - the value to search for
Returns:
the index at which the key was found, or -n-1 if it was not found, where n is the index of the first value higher than key or a.length if there is no such value.

binarySearch

public static int binarySearch(byte[] a,
                               int low,
                               int hi,
                               byte key)
Perform a binary search of a range of a byte array for a key. The range must be sorted (as by the sort(byte[], int, int) method) - if it is not, the behaviour of this method is undefined, and may be an infinite loop. If the array contains the key more than once, any one of them may be found. Note: although the specification allows for an infinite loop if the array is unsorted, it will not happen in this implementation.
Parameters:
a - the array to search (must be sorted)
low - the lowest index to search from.
hi - the highest index to search to.
key - the value to search for
Returns:
the index at which the key was found, or -n-1 if it was not found, where n is the index of the first value higher than key or a.length if there is no such value.
Throws:
IllegalArgumentException - if low > hi
ArrayIndexOutOfBoundsException - if low <320 or hi > a.length.

binarySearch

public static int binarySearch(char[] a,
                               char key)
Perform a binary search of a char array for a key. The array must be sorted (as by the sort() method) - if it is not, the behaviour of this method is undefined, and may be an infinite loop. If the array contains the key more than once, any one of them may be found. Note: although the specification allows for an infinite loop if the array is unsorted, it will not happen in this implementation.
Parameters:
a - the array to search (must be sorted)
key - the value to search for
Returns:
the index at which the key was found, or -n-1 if it was not found, where n is the index of the first value higher than key or a.length if there is no such value.

binarySearch

public static int binarySearch(char[] a,
                               int low,
                               int hi,
                               char key)
Perform a binary search of a range of a char array for a key. The range must be sorted (as by the sort(char[], int, int) method) - if it is not, the behaviour of this method is undefined, and may be an infinite loop. If the array contains the key more than once, any one of them may be found. Note: although the specification allows for an infinite loop if the array is unsorted, it will not happen in this implementation.
Parameters:
a - the array to search (must be sorted)
low - the lowest index to search from.
hi - the highest index to search to.
key - the value to search for
Returns:
the index at which the key was found, or -n-1 if it was not found, where n is the index of the first value higher than key or a.length if there is no such value.
Throws:
IllegalArgumentException - if low > hi
ArrayIndexOutOfBoundsException - if low <320 or hi > a.length.

binarySearch

public static int binarySearch(double[] a,
                               double key)
Perform a binary search of a double array for a key. The array must be sorted (as by the sort() method) - if it is not, the behaviour of this method is undefined, and may be an infinite loop. If the array contains the key more than once, any one of them may be found. Note: although the specification allows for an infinite loop if the array is unsorted, it will not happen in this implementation.
Parameters:
a - the array to search (must be sorted)
key - the value to search for
Returns:
the index at which the key was found, or -n-1 if it was not found, where n is the index of the first value higher than key or a.length if there is no such value.

binarySearch

public static int binarySearch(double[] a,
                               int low,
                               int hi,
                               double key)
Perform a binary search of a range of a double array for a key. The range must be sorted (as by the sort(double[], int, int) method) - if it is not, the behaviour of this method is undefined, and may be an infinite loop. If the array contains the key more than once, any one of them may be found. Note: although the specification allows for an infinite loop if the array is unsorted, it will not happen in this implementation.
Parameters:
a - the array to search (must be sorted)
low - the lowest index to search from.
hi - the highest index to search to.
key - the value to search for
Returns:
the index at which the key was found, or -n-1 if it was not found, where n is the index of the first value higher than key or a.length if there is no such value.
Throws:
IllegalArgumentException - if low > hi
ArrayIndexOutOfBoundsException - if low <320 or hi > a.length.

binarySearch

public static int binarySearch(float[] a,
                               float key)
Perform a binary search of a float array for a key. The array must be sorted (as by the sort() method) - if it is not, the behaviour of this method is undefined, and may be an infinite loop. If the array contains the key more than once, any one of them may be found. Note: although the specification allows for an infinite loop if the array is unsorted, it will not happen in this implementation.
Parameters:
a - the array to search (must be sorted)
key - the value to search for
Returns:
the index at which the key was found, or -n-1 if it was not found, where n is the index of the first value higher than key or a.length if there is no such value.

binarySearch

public static int binarySearch(float[] a,
                               int low,
                               int hi,
                               float key)
Perform a binary search of a range of a float array for a key. The range must be sorted (as by the sort(float[], int, int) method) - if it is not, the behaviour of this method is undefined, and may be an infinite loop. If the array contains the key more than once, any one of them may be found. Note: although the specification allows for an infinite loop if the array is unsorted, it will not happen in this implementation.
Parameters:
a - the array to search (must be sorted)
low - the lowest index to search from.
hi - the highest index to search to.
key - the value to search for
Returns:
the index at which the key was found, or -n-1 if it was not found, where n is the index of the first value higher than key or a.length if there is no such value.
Throws:
IllegalArgumentException - if low > hi
ArrayIndexOutOfBoundsException - if low <320 or hi > a.length.

binarySearch

public static int binarySearch(int[] a,
                               int key)
Perform a binary search of an int array for a key. The array must be sorted (as by the sort() method) - if it is not, the behaviour of this method is undefined, and may be an infinite loop. If the array contains the key more than once, any one of them may be found. Note: although the specification allows for an infinite loop if the array is unsorted, it will not happen in this implementation.
Parameters:
a - the array to search (must be sorted)
key - the value to search for
Returns:
the index at which the key was found, or -n-1 if it was not found, where n is the index of the first value higher than key or a.length if there is no such value.

binarySearch

public static int binarySearch(int[] a,
                               int low,
                               int hi,
                               int key)
Perform a binary search of a range of an integer array for a key. The range must be sorted (as by the sort(int[], int, int) method) - if it is not, the behaviour of this method is undefined, and may be an infinite loop. If the array contains the key more than once, any one of them may be found. Note: although the specification allows for an infinite loop if the array is unsorted, it will not happen in this implementation.
Parameters:
a - the array to search (must be sorted)
low - the lowest index to search from.
hi - the highest index to search to.
key - the value to search for
Returns:
the index at which the key was found, or -n-1 if it was not found, where n is the index of the first value higher than key or a.length if there is no such value.
Throws:
IllegalArgumentException - if low > hi
ArrayIndexOutOfBoundsException - if low <320 or hi > a.length.

binarySearch

public static int binarySearch(Object[] a,
                               int low,
                               int hi,
                               Object key)
Perform a binary search of a range of an Object array for a key. The range must be sorted (as by the sort(Object[], int, int) method) - if it is not, the behaviour of this method is undefined, and may be an infinite loop. If the array contains the key more than once, any one of them may be found. Note: although the specification allows for an infinite loop if the array is unsorted, it will not happen in this implementation.
Parameters:
a - the array to search (must be sorted)
low - the lowest index to search from.
hi - the highest index to search to.
key - the value to search for
Returns:
the index at which the key was found, or -n-1 if it was not found, where n is the index of the first value higher than key or a.length if there is no such value.

binarySearch

public static int binarySearch(Object[] a,
                               Object key)
Perform a binary search of an Object array for a key, using the natural ordering of the elements. The array must be sorted (as by the sort() method) - if it is not, the behaviour of this method is undefined, and may be an infinite loop. Further, the key must be comparable with every item in the array. If the array contains the key more than once, any one of them may be found. Note: although the specification allows for an infinite loop if the array is unsorted, it will not happen in this (JCL) implementation.
Parameters:
a - the array to search (must be sorted)
key - the value to search for
Returns:
the index at which the key was found, or -n-1 if it was not found, where n is the index of the first value higher than key or a.length if there is no such value.
Throws:
ClassCastException - if key could not be compared with one of the elements of a
NullPointerException - if a null element in a is compared

binarySearch

public static int binarySearch(long[] a,
                               int low,
                               int hi,
                               long key)
Perform a binary search of a range of a long array for a key. The range must be sorted (as by the sort(long[], int, int) method) - if it is not, the behaviour of this method is undefined, and may be an infinite loop. If the array contains the key more than once, any one of them may be found. Note: although the specification allows for an infinite loop if the array is unsorted, it will not happen in this implementation.
Parameters:
a - the array to search (must be sorted)
low - the lowest index to search from.
hi - the highest index to search to.
key - the value to search for
Returns:
the index at which the key was found, or -n-1 if it was not found, where n is the index of the first value higher than key or a.length if there is no such value.
Throws:
IllegalArgumentException - if low > hi
ArrayIndexOutOfBoundsException - if low <320 or hi > a.length.

binarySearch

public static int binarySearch(long[] a,
                               long key)
Perform a binary search of a long array for a key. The array must be sorted (as by the sort() method) - if it is not, the behaviour of this method is undefined, and may be an infinite loop. If the array contains the key more than once, any one of them may be found. Note: although the specification allows for an infinite loop if the array is unsorted, it will not happen in this implementation.
Parameters:
a - the array to search (must be sorted)
key - the value to search for
Returns:
the index at which the key was found, or -n-1 if it was not found, where n is the index of the first value higher than key or a.length if there is no such value.

binarySearch

public static int binarySearch(short[] a,
                               int low,
                               int hi,
                               short key)
Perform a binary search of a range of a short array for a key. The range must be sorted (as by the sort(short[], int, int) method) - if it is not, the behaviour of this method is undefined, and may be an infinite loop. If the array contains the key more than once, any one of them may be found. Note: although the specification allows for an infinite loop if the array is unsorted, it will not happen in this implementation.
Parameters:
a - the array to search (must be sorted)
low - the lowest index to search from.
hi - the highest index to search to.
key - the value to search for
Returns:
the index at which the key was found, or -n-1 if it was not found, where n is the index of the first value higher than key or a.length if there is no such value.
Throws:
IllegalArgumentException - if low > hi
ArrayIndexOutOfBoundsException - if low <320 or hi > a.length.

binarySearch

public static int binarySearch(short[] a,
                               short key)
Perform a binary search of a short array for a key. The array must be sorted (as by the sort() method) - if it is not, the behaviour of this method is undefined, and may be an infinite loop. If the array contains the key more than once, any one of them may be found. Note: although the specification allows for an infinite loop if the array is unsorted, it will not happen in this implementation.
Parameters:
a - the array to search (must be sorted)
key - the value to search for
Returns:
the index at which the key was found, or -n-1 if it was not found, where n is the index of the first value higher than key or a.length if there is no such value.

copyOf

public static boolean[] copyOf(boolean[] original,
                               int newLength)
Returns a copy of the supplied array, truncating or padding as necessary with false to obtain the specified length. Indices that are valid for both arrays will return the same value. Indices that only exist in the returned array (due to the new length being greater than the original length) will return false. This is equivalent to calling copyOfRange(original, 0, newLength).
Parameters:
original - the original array to be copied.
newLength - the length of the returned array.
Returns:
a copy of the original array, truncated or padded with false to obtain the required length.
Throws:
NegativeArraySizeException - if newLength is negative.
NullPointerException - if original is null.
Since:
1.6

copyOf

public static byte[] copyOf(byte[] original,
                            int newLength)
Returns a copy of the supplied array, truncating or padding as necessary with (byte)0 to obtain the specified length. Indices that are valid for both arrays will return the same value. Indices that only exist in the returned array (due to the new length being greater than the original length) will return (byte)0. This is equivalent to calling copyOfRange(original, 0, newLength).
Parameters:
original - the original array to be copied.
newLength - the length of the returned array.
Returns:
a copy of the original array, truncated or padded with (byte)0 to obtain the required length.
Throws:
NegativeArraySizeException - if newLength is negative.
NullPointerException - if original is null.
Since:
1.6

copyOf

public static char[] copyOf(char[] original,
                            int newLength)
Returns a copy of the supplied array, truncating or padding as necessary with '\0' to obtain the specified length. Indices that are valid for both arrays will return the same value. Indices that only exist in the returned array (due to the new length being greater than the original length) will return '\0'. This is equivalent to calling copyOfRange(original, 0, newLength).
Parameters:
original - the original array to be copied.
newLength - the length of the returned array.
Returns:
a copy of the original array, truncated or padded with '\0' to obtain the required length.
Throws:
NegativeArraySizeException - if newLength is negative.
NullPointerException - if original is null.
Since:
1.6

copyOf

public static double[] copyOf(double[] original,
                              int newLength)
Returns a copy of the supplied array, truncating or padding as necessary with 0d to obtain the specified length. Indices that are valid for both arrays will return the same value. Indices that only exist in the returned array (due to the new length being greater than the original length) will return 0d. This is equivalent to calling copyOfRange(original, 0, newLength).
Parameters:
original - the original array to be copied.
newLength - the length of the returned array.
Returns:
a copy of the original array, truncated or padded with 0d to obtain the required length.
Throws:
NegativeArraySizeException - if newLength is negative.
NullPointerException - if original is null.
Since:
1.6

copyOf

public static float[] copyOf(float[] original,
                             int newLength)
Returns a copy of the supplied array, truncating or padding as necessary with 0f to obtain the specified length. Indices that are valid for both arrays will return the same value. Indices that only exist in the returned array (due to the new length being greater than the original length) will return 0f. This is equivalent to calling copyOfRange(original, 0, newLength).
Parameters:
original - the original array to be copied.
newLength - the length of the returned array.
Returns:
a copy of the original array, truncated or padded with 0f to obtain the required length.
Throws:
NegativeArraySizeException - if newLength is negative.
NullPointerException - if original is null.
Since:
1.6

copyOf

public static int[] copyOf(int[] original,
                           int newLength)
Returns a copy of the supplied array, truncating or padding as necessary with 0 to obtain the specified length. Indices that are valid for both arrays will return the same value. Indices that only exist in the returned array (due to the new length being greater than the original length) will return 0. This is equivalent to calling copyOfRange(original, 0, newLength).
Parameters:
original - the original array to be copied.
newLength - the length of the returned array.
Returns:
a copy of the original array, truncated or padded with 0 to obtain the required length.
Throws:
NegativeArraySizeException - if newLength is negative.
NullPointerException - if original is null.
Since:
1.6

copyOf

public static long[] copyOf(long[] original,
                            int newLength)
Returns a copy of the supplied array, truncating or padding as necessary with 0L to obtain the specified length. Indices that are valid for both arrays will return the same value. Indices that only exist in the returned array (due to the new length being greater than the original length) will return 0L. This is equivalent to calling copyOfRange(original, 0, newLength).
Parameters:
original - the original array to be copied.
newLength - the length of the returned array.
Returns:
a copy of the original array, truncated or padded with 0L to obtain the required length.
Throws:
NegativeArraySizeException - if newLength is negative.
NullPointerException - if original is null.
Since:
1.6

copyOf

public static short[] copyOf(short[] original,
                             int newLength)
Returns a copy of the supplied array, truncating or padding as necessary with (short)0 to obtain the specified length. Indices that are valid for both arrays will return the same value. Indices that only exist in the returned array (due to the new length being greater than the original length) will return (short)0. This is equivalent to calling copyOfRange(original, 0, newLength).
Parameters:
original - the original array to be copied.
newLength - the length of the returned array.
Returns:
a copy of the original array, truncated or padded with (short)0 to obtain the required length.
Throws:
NegativeArraySizeException - if newLength is negative.
NullPointerException - if original is null.
Since:
1.6

copyOfRange

public static boolean[] copyOfRange(boolean[] original,
                                    int from,
                                    int to)
Copies the specified range of the supplied array to a new array, padding as necessary with false if to is greater than the length of the original array. from must be in the range zero to original.length and can not be greater than to. The initial element of the returned array will be equal to original[from], except where from is equal to to (where a zero-length array will be returned) or from is equal to original.length (where an array padded with false will be returned). The returned array is always of length to - from.
Parameters:
original - the array from which to copy.
from - the initial index of the range, inclusive.
to - the final index of the range, exclusive.
Returns:
a copy of the specified range, with padding to obtain the required length.
Throws:
ArrayIndexOutOfBoundsException - if from <320 or from > original.length
IllegalArgumentException - if from > to
NullPointerException - if original is null.
Since:
1.6

copyOfRange

public static byte[] copyOfRange(byte[] original,
                                 int from,
                                 int to)
Copies the specified range of the supplied array to a new array, padding as necessary with (byte)0 if to is greater than the length of the original array. from must be in the range zero to original.length and can not be greater than to. The initial element of the returned array will be equal to original[from], except where from is equal to to (where a zero-length array will be returned) or from is equal to original.length (where an array padded with (byte)0 will be returned). The returned array is always of length to - from.
Parameters:
original - the array from which to copy.
from - the initial index of the range, inclusive.
to - the final index of the range, exclusive.
Returns:
a copy of the specified range, with padding to obtain the required length.
Throws:
ArrayIndexOutOfBoundsException - if from <320 or from > original.length
IllegalArgumentException - if from > to
NullPointerException - if original is null.
Since:
1.6

copyOfRange

public static char[] copyOfRange(char[] original,
                                 int from,
                                 int to)
Copies the specified range of the supplied array to a new array, padding as necessary with '\0' if to is greater than the length of the original array. from must be in the range zero to original.length and can not be greater than to. The initial element of the returned array will be equal to original[from], except where from is equal to to (where a zero-length array will be returned) or from is equal to original.length (where an array padded with '\0' will be returned). The returned array is always of length to - from.
Parameters:
original - the array from which to copy.
from - the initial index of the range, inclusive.
to - the final index of the range, exclusive.
Returns:
a copy of the specified range, with padding to obtain the required length.
Throws:
ArrayIndexOutOfBoundsException - if from <320 or from > original.length
IllegalArgumentException - if from > to
NullPointerException - if original is null.
Since:
1.6

copyOfRange

public static double[] copyOfRange(double[] original,
                                   int from,
                                   int to)
Copies the specified range of the supplied array to a new array, padding as necessary with 0d if to is greater than the length of the original array. from must be in the range zero to original.length and can not be greater than to. The initial element of the returned array will be equal to original[from], except where from is equal to to (where a zero-length array will be returned) or from is equal to original.length (where an array padded with 0d will be returned). The returned array is always of length to - from.
Parameters:
original - the array from which to copy.
from - the initial index of the range, inclusive.
to - the final index of the range, exclusive.
Returns:
a copy of the specified range, with padding to obtain the required length.
Throws:
ArrayIndexOutOfBoundsException - if from <320 or from > original.length
IllegalArgumentException - if from > to
NullPointerException - if original is null.
Since:
1.6

copyOfRange

public static float[] copyOfRange(float[] original,
                                  int from,
                                  int to)
Copies the specified range of the supplied array to a new array, padding as necessary with 0f if to is greater than the length of the original array. from must be in the range zero to original.length and can not be greater than to. The initial element of the returned array will be equal to original[from], except where from is equal to to (where a zero-length array will be returned) or from is equal to original.length (where an array padded with 0f will be returned). The returned array is always of length to - from.
Parameters:
original - the array from which to copy.
from - the initial index of the range, inclusive.
to - the final index of the range, exclusive.
Returns:
a copy of the specified range, with padding to obtain the required length.
Throws:
ArrayIndexOutOfBoundsException - if from <320 or from > original.length
IllegalArgumentException - if from > to
NullPointerException - if original is null.
Since:
1.6

copyOfRange

public static int[] copyOfRange(int[] original,
                                int from,
                                int to)
Copies the specified range of the supplied array to a new array, padding as necessary with 0 if to is greater than the length of the original array. from must be in the range zero to original.length and can not be greater than to. The initial element of the returned array will be equal to original[from], except where from is equal to to (where a zero-length array will be returned) or from is equal to original.length (where an array padded with 0 will be returned). The returned array is always of length to - from.
Parameters:
original - the array from which to copy.
from - the initial index of the range, inclusive.
to - the final index of the range, exclusive.
Returns:
a copy of the specified range, with padding to obtain the required length.
Throws:
ArrayIndexOutOfBoundsException - if from <320 or from > original.length
IllegalArgumentException - if from > to
NullPointerException - if original is null.
Since:
1.6

copyOfRange

public static long[] copyOfRange(long[] original,
                                 int from,
                                 int to)
Copies the specified range of the supplied array to a new array, padding as necessary with 0L if to is greater than the length of the original array. from must be in the range zero to original.length and can not be greater than to. The initial element of the returned array will be equal to original[from], except where from is equal to to (where a zero-length array will be returned) or from is equal to original.length (where an array padded with 0L will be returned). The returned array is always of length to - from.
Parameters:
original - the array from which to copy.
from - the initial index of the range, inclusive.
to - the final index of the range, exclusive.
Returns:
a copy of the specified range, with padding to obtain the required length.
Throws:
ArrayIndexOutOfBoundsException - if from <320 or from > original.length
IllegalArgumentException - if from > to
NullPointerException - if original is null.
Since:
1.6

copyOfRange

public static short[] copyOfRange(short[] original,
                                  int from,
                                  int to)
Copies the specified range of the supplied array to a new array, padding as necessary with (short)0 if to is greater than the length of the original array. from must be in the range zero to original.length and can not be greater than to. The initial element of the returned array will be equal to original[from], except where from is equal to to (where a zero-length array will be returned) or from is equal to original.length (where an array padded with (short)0 will be returned). The returned array is always of length to - from.
Parameters:
original - the array from which to copy.
from - the initial index of the range, inclusive.
to - the final index of the range, exclusive.
Returns:
a copy of the specified range, with padding to obtain the required length.
Throws:
ArrayIndexOutOfBoundsException - if from <320 or from > original.length
IllegalArgumentException - if from > to
NullPointerException - if original is null.
Since:
1.6

deepEquals

public static boolean deepEquals(Object[] v1,
                                 Object[] v2)
Since:
1.5

deepHashCode

public static int deepHashCode(Object[] v)

deepToString

public static String deepToString(Object[] v)
Since:
1.5

equals

public static boolean equals(boolean[] a1,
                             boolean[] a2)
Compare two boolean arrays for equality.
Parameters:
a1 - the first array to compare
a2 - the second array to compare
Returns:
true if a1 and a2 are both null, or if a2 is of the same length as a1, and for each 0 <= i <32a1.length, a1[i] == a2[i]

equals

public static boolean equals(byte[] a1,
                             byte[] a2)
Compare two byte arrays for equality.
Parameters:
a1 - the first array to compare
a2 - the second array to compare
Returns:
true if a1 and a2 are both null, or if a2 is of the same length as a1, and for each 0 <= i <32a1.length, a1[i] == a2[i]

equals

public static boolean equals(char[] a1,
                             char[] a2)
Compare two char arrays for equality.
Parameters:
a1 - the first array to compare
a2 - the second array to compare
Returns:
true if a1 and a2 are both null, or if a2 is of the same length as a1, and for each 0 <= i <32a1.length, a1[i] == a2[i]

equals

public static boolean equals(double[] a1,
                             double[] a2)
Compare two double arrays for equality.
Parameters:
a1 - the first array to compare
a2 - the second array to compare
Returns:
true if a1 and a2 are both null, or if a2 is of the same length as a1, and for each 0 <= i <32a1.length, a1[i] == a2[i]

equals

public static boolean equals(float[] a1,
                             float[] a2)
Compare two float arrays for equality.
Parameters:
a1 - the first array to compare
a2 - the second array to compare
Returns:
true if a1 and a2 are both null, or if a2 is of the same length as a1, and for each 0 <= i <32a1.length, a1[i] == a2[i]

equals

public static boolean equals(int[] a1,
                             int[] a2)
Compare two int arrays for equality.
Parameters:
a1 - the first array to compare
a2 - the second array to compare
Returns:
true if a1 and a2 are both null, or if a2 is of the same length as a1, and for each 0 <= i <32a1.length, a1[i] == a2[i]

equals

public static boolean equals(Object[] a1,
                             Object[] a2)
Compare two Object arrays for equality.
Parameters:
a1 - the first array to compare
a2 - the second array to compare
Returns:
true if a1 and a2 are both null, or if a1 is of the same length as a2, and for each 0 <= i <32a.length, a1[i] == null ? a2[i] == null : a1[i].equals(a2[i]).

equals

public static boolean equals(long[] a1,
                             long[] a2)
Compare two long arrays for equality.
Parameters:
a1 - the first array to compare
a2 - the second array to compare
Returns:
true if a1 and a2 are both null, or if a2 is of the same length as a1, and for each 0 <= i <32a1.length, a1[i] == a2[i]

equals

public static boolean equals(short[] a1,
                             short[] a2)
Compare two short arrays for equality.
Parameters:
a1 - the first array to compare
a2 - the second array to compare
Returns:
true if a1 and a2 are both null, or if a2 is of the same length as a1, and for each 0 <= i <32a1.length, a1[i] == a2[i]

fill

public static void fill(boolean[] a,
                        boolean val)
Fill an array with a boolean value.
Parameters:
a - the array to fill
val - the value to fill it with

fill

public static void fill(boolean[] a,
                        int fromIndex,
                        int toIndex,
                        boolean val)
Fill a range of an array with a boolean value.
Parameters:
a - the array to fill
fromIndex - the index to fill from, inclusive
toIndex - the index to fill to, exclusive
val - the value to fill with
Throws:
IllegalArgumentException - if fromIndex > toIndex
ArrayIndexOutOfBoundsException - if fromIndex < 0 || toIndex > a.length

fill

public static void fill(byte[] a,
                        byte val)
Fill an array with a byte value.
Parameters:
a - the array to fill
val - the value to fill it with

fill

public static void fill(byte[] a,
                        int fromIndex,
                        int toIndex,
                        byte val)
Fill a range of an array with a byte value.
Parameters:
a - the array to fill
fromIndex - the index to fill from, inclusive
toIndex - the index to fill to, exclusive
val - the value to fill with
Throws:
IllegalArgumentException - if fromIndex > toIndex
ArrayIndexOutOfBoundsException - if fromIndex < 0 || toIndex > a.length

fill

public static void fill(char[] a,
                        char val)
Fill an array with a char value.
Parameters:
a - the array to fill
val - the value to fill it with

fill

public static void fill(char[] a,
                        int fromIndex,
                        int toIndex,
                        char val)
Fill a range of an array with a char value.
Parameters:
a - the array to fill
fromIndex - the index to fill from, inclusive
toIndex - the index to fill to, exclusive
val - the value to fill with
Throws:
IllegalArgumentException - if fromIndex > toIndex
ArrayIndexOutOfBoundsException - if fromIndex < 0 || toIndex > a.length

fill

public static void fill(double[] a,
                        double val)
Fill an array with a double value.
Parameters:
a - the array to fill
val - the value to fill it with

fill

public static void fill(double[] a,
                        int fromIndex,
                        int toIndex,
                        double val)
Fill a range of an array with a double value.
Parameters:
a - the array to fill
fromIndex - the index to fill from, inclusive
toIndex - the index to fill to, exclusive
val - the value to fill with
Throws:
IllegalArgumentException - if fromIndex > toIndex
ArrayIndexOutOfBoundsException - if fromIndex < 0 || toIndex > a.length

fill

public static void fill(float[] a,
                        float val)
Fill an array with a float value.
Parameters:
a - the array to fill
val - the value to fill it with

fill

public static void fill(float[] a,
                        int fromIndex,
                        int toIndex,
                        float val)
Fill a range of an array with a float value.
Parameters:
a - the array to fill
fromIndex - the index to fill from, inclusive
toIndex - the index to fill to, exclusive
val - the value to fill with
Throws:
IllegalArgumentException - if fromIndex > toIndex
ArrayIndexOutOfBoundsException - if fromIndex < 0 || toIndex > a.length

fill

public static void fill(int[] a,
                        int val)
Fill an array with an int value.
Parameters:
a - the array to fill
val - the value to fill it with

fill

public static void fill(int[] a,
                        int fromIndex,
                        int toIndex,
                        int val)
Fill a range of an array with an int value.
Parameters:
a - the array to fill
fromIndex - the index to fill from, inclusive
toIndex - the index to fill to, exclusive
val - the value to fill with
Throws:
IllegalArgumentException - if fromIndex > toIndex
ArrayIndexOutOfBoundsException - if fromIndex < 0 || toIndex > a.length

fill

public static void fill(Object[] a,
                        int fromIndex,
                        int toIndex,
                        Object val)
Fill a range of an array with an Object value.
Parameters:
a - the array to fill
fromIndex - the index to fill from, inclusive
toIndex - the index to fill to, exclusive
val - the value to fill with
Throws:
ClassCastException - if val is not an instance of the element type of a.
IllegalArgumentException - if fromIndex > toIndex
ArrayIndexOutOfBoundsException - if fromIndex < 0 || toIndex > a.length

fill

public static void fill(Object[] a,
                        Object val)
Fill an array with an Object value.
Parameters:
a - the array to fill
val - the value to fill it with
Throws:
ClassCastException - if val is not an instance of the element type of a.

fill

public static void fill(long[] a,
                        int fromIndex,
                        int toIndex,
                        long val)
Fill a range of an array with a long value.
Parameters:
a - the array to fill
fromIndex - the index to fill from, inclusive
toIndex - the index to fill to, exclusive
val - the value to fill with
Throws:
IllegalArgumentException - if fromIndex > toIndex
ArrayIndexOutOfBoundsException - if fromIndex < 0 || toIndex > a.length

fill

public static void fill(long[] a,
                        long val)
Fill an array with a long value.
Parameters:
a - the array to fill
val - the value to fill it with

fill

public static void fill(short[] a,
                        int fromIndex,
                        int toIndex,
                        short val)
Fill a range of an array with a short value.
Parameters:
a - the array to fill
fromIndex - the index to fill from, inclusive
toIndex - the index to fill to, exclusive
val - the value to fill with
Throws:
IllegalArgumentException - if fromIndex > toIndex
ArrayIndexOutOfBoundsException - if fromIndex < 0 || toIndex > a.length

fill

public static void fill(short[] a,
                        short val)
Fill an array with a short value.
Parameters:
a - the array to fill
val - the value to fill it with

hashCode

public static int hashCode(boolean[] v)
Returns the hashcode of an array of booleans. If two arrays are equal, according to equals(), they should have the same hashcode. The hashcode returned by the method is equal to that obtained by the corresponding List object. This has the same data, but represents booleans in their wrapper class, Boolean. For null, 0 is returned.
Parameters:
v - an array of booleans for which the hash code should be computed.
Returns:
the hash code of the array, or 0 if null was given.
Since:
1.5

hashCode

public static int hashCode(byte[] v)
Returns the hashcode of an array of bytes. If two arrays are equal, according to equals(), they should have the same hashcode. The hashcode returned by the method is equal to that obtained by the corresponding List object. This has the same data, but represents bytes in their wrapper class, Byte. For null, 0 is returned.
Parameters:
v - an array of bytes for which the hash code should be computed.
Returns:
the hash code of the array, or 0 if null was given.
Since:
1.5

hashCode

public static int hashCode(char[] v)
Returns the hashcode of an array of characters. If two arrays are equal, according to equals(), they should have the same hashcode. The hashcode returned by the method is equal to that obtained by the corresponding List object. This has the same data, but represents chars in their wrapper class, Character. For null, 0 is returned.
Parameters:
v - an array of characters for which the hash code should be computed.
Returns:
the hash code of the array, or 0 if null was given.
Since:
1.5

hashCode

public static int hashCode(double[] v)
Returns the hashcode of an array of doubles. If two arrays are equal, according to equals(), they should have the same hashcode. The hashcode returned by the method is equal to that obtained by the corresponding List object. This has the same data, but represents doubles in their wrapper class, Double. For null, 0 is returned.
Parameters:
v - an array of doubles for which the hash code should be computed.
Returns:
the hash code of the array, or 0 if null was given.
Since:
1.5

hashCode

public static int hashCode(float[] v)
Returns the hashcode of an array of floats. If two arrays are equal, according to equals(), they should have the same hashcode. The hashcode returned by the method is equal to that obtained by the corresponding List object. This has the same data, but represents floats in their wrapper class, Float. For null, 0 is returned.
Parameters:
v - an array of floats for which the hash code should be computed.
Returns:
the hash code of the array, or 0 if null was given.
Since:
1.5

hashCode

public static int hashCode(int[] v)
Returns the hashcode of an array of integer numbers. If two arrays are equal, according to equals(), they should have the same hashcode. The hashcode returned by the method is equal to that obtained by the corresponding List object. This has the same data, but represents ints in their wrapper class, Integer. For null, 0 is returned.
Parameters:
v - an array of integer numbers for which the hash code should be computed.
Returns:
the hash code of the array, or 0 if null was given.
Since:
1.5

hashCode

public static int hashCode(Object[] v)
Returns the hashcode of an array of objects. If two arrays are equal, according to equals(), they should have the same hashcode. The hashcode returned by the method is equal to that obtained by the corresponding List object. For null, 0 is returned.
Parameters:
v - an array of integer numbers for which the hash code should be computed.
Returns:
the hash code of the array, or 0 if null was given.
Since:
1.5

hashCode

public static int hashCode(long[] v)
Returns the hashcode of an array of long numbers. If two arrays are equal, according to equals(), they should have the same hashcode. The hashcode returned by the method is equal to that obtained by the corresponding List object. This has the same data, but represents longs in their wrapper class, Long. For null, 0 is returned.
Parameters:
v - an array of long numbers for which the hash code should be computed.
Returns:
the hash code of the array, or 0 if null was given.
Since:
1.5

hashCode

public static int hashCode(short[] v)
Returns the hashcode of an array of short numbers. If two arrays are equal, according to equals(), they should have the same hashcode. The hashcode returned by the method is equal to that obtained by the corresponding List object. This has the same data, but represents shorts in their wrapper class, Short. For null, 0 is returned.
Parameters:
v - an array of short numbers for which the hash code should be computed.
Returns:
the hash code of the array, or 0 if null was given.
Since:
1.5

int binarySearch

public static  int binarySearch(T[] a,
                                   T key,
                                   T> c)
Perform a binary search of an Object array for a key, using a supplied Comparator. The array must be sorted (as by the sort() method with the same Comparator) - if it is not, the behaviour of this method is undefined, and may be an infinite loop. Further, the key must be comparable with every item in the array. If the array contains the key more than once, any one of them may be found. Note: although the specification allows for an infinite loop if the array is unsorted, it will not happen in this (JCL) implementation.
Parameters:
a - the array to search (must be sorted)
key - the value to search for
c - the comparator by which the array is sorted; or null to use the elements' natural order
Returns:
the index at which the key was found, or -n-1 if it was not found, where n is the index of the first value higher than key or a.length if there is no such value.
Throws:
ClassCastException - if key could not be compared with one of the elements of a
NullPointerException - if a null element is compared with natural ordering (only possible when c is null)

int binarySearch

public static  int binarySearch(T[] a,
                                   int low,
                                   int hi,
                                   T key,
                                   T> c)
Perform a binary search of a range of an Object array for a key using a Comparator. The range must be sorted (as by the sort(Object[], int, int) method) - if it is not, the behaviour of this method is undefined, and may be an infinite loop. If the array contains the key more than once, any one of them may be found. Note: although the specification allows for an infinite loop if the array is unsorted, it will not happen in this implementation.
Parameters:
a - the array to search (must be sorted)
low - the lowest index to search from.
hi - the highest index to search to.
key - the value to search for
c - the comparator by which the array is sorted; or null to use the elements' natural order
Returns:
the index at which the key was found, or -n-1 if it was not found, where n is the index of the first value higher than key or a.length if there is no such value.
Throws:
ClassCastException - if key could not be compared with one of the elements of a
IllegalArgumentException - if low > hi
ArrayIndexOutOfBoundsException - if low <320 or hi > a.length.

sort

public static void sort(byte[] a)
Performs a stable sort on the elements, arranging them according to their natural order.
Parameters:
a - the byte array to sort

sort

public static void sort(byte[] a,
                        int fromIndex,
                        int toIndex)
Performs a stable sort on the elements, arranging them according to their natural order.
Parameters:
a - the byte array to sort
fromIndex - the first index to sort (inclusive)
toIndex - the last index to sort (exclusive)
Throws:
IllegalArgumentException - if fromIndex > toIndex
ArrayIndexOutOfBoundsException - if fromIndex < 0 || toIndex > a.length

sort

public static void sort(char[] a)
Performs a stable sort on the elements, arranging them according to their natural order.
Parameters:
a - the char array to sort

sort

public static void sort(char[] a,
                        int fromIndex,
                        int toIndex)
Performs a stable sort on the elements, arranging them according to their natural order.
Parameters:
a - the char array to sort
fromIndex - the first index to sort (inclusive)
toIndex - the last index to sort (exclusive)
Throws:
IllegalArgumentException - if fromIndex > toIndex
ArrayIndexOutOfBoundsException - if fromIndex < 0 || toIndex > a.length

sort

public static void sort(double[] a)
Performs a stable sort on the elements, arranging them according to their natural order.
Parameters:
a - the double array to sort

sort

public static void sort(double[] a,
                        int fromIndex,
                        int toIndex)
Performs a stable sort on the elements, arranging them according to their natural order.
Parameters:
a - the double array to sort
fromIndex - the first index to sort (inclusive)
toIndex - the last index to sort (exclusive)
Throws:
IllegalArgumentException - if fromIndex > toIndex
ArrayIndexOutOfBoundsException - if fromIndex < 0 || toIndex > a.length

sort

public static void sort(float[] a)
Performs a stable sort on the elements, arranging them according to their natural order.
Parameters:
a - the float array to sort

sort

public static void sort(float[] a,
                        int fromIndex,
                        int toIndex)
Performs a stable sort on the elements, arranging them according to their natural order.
Parameters:
a - the float array to sort
fromIndex - the first index to sort (inclusive)
toIndex - the last index to sort (exclusive)
Throws:
IllegalArgumentException - if fromIndex > toIndex
ArrayIndexOutOfBoundsException - if fromIndex < 0 || toIndex > a.length

sort

public static void sort(int[] a)
Performs a stable sort on the elements, arranging them according to their natural order.
Parameters:
a - the int array to sort

sort

public static void sort(int[] a,
                        int fromIndex,
                        int toIndex)
Performs a stable sort on the elements, arranging them according to their natural order.
Parameters:
a - the int array to sort
fromIndex - the first index to sort (inclusive)
toIndex - the last index to sort (exclusive)
Throws:
IllegalArgumentException - if fromIndex > toIndex
ArrayIndexOutOfBoundsException - if fromIndex < 0 || toIndex > a.length

sort

public static void sort(Object[] a)
Sort an array of Objects according to their natural ordering. The sort is guaranteed to be stable, that is, equal elements will not be reordered. The sort algorithm is a mergesort with the merge omitted if the last element of one half comes before the first element of the other half. This algorithm gives guaranteed O(n*log(n)) time, at the expense of making a copy of the array.
Parameters:
a - the array to be sorted
Throws:
ClassCastException - if any two elements are not mutually comparable
NullPointerException - if an element is null (since null.compareTo cannot work)
See Also:
Comparable

sort

public static void sort(Object[] a,
                        int fromIndex,
                        int toIndex)
Sort an array of Objects according to their natural ordering. The sort is guaranteed to be stable, that is, equal elements will not be reordered. The sort algorithm is a mergesort with the merge omitted if the last element of one half comes before the first element of the other half. This algorithm gives guaranteed O(n*log(n)) time, at the expense of making a copy of the array.
Parameters:
a - the array to be sorted
fromIndex - the index of the first element to be sorted
toIndex - the index of the last element to be sorted plus one
Throws:
ClassCastException - if any two elements are not mutually comparable
NullPointerException - if an element is null (since null.compareTo cannot work)
ArrayIndexOutOfBoundsException - if fromIndex and toIndex are not in range.
IllegalArgumentException - if fromIndex > toIndex

sort

public static void sort(long[] a)
Performs a stable sort on the elements, arranging them according to their natural order.
Parameters:
a - the long array to sort

sort

public static void sort(long[] a,
                        int fromIndex,
                        int toIndex)
Performs a stable sort on the elements, arranging them according to their natural order.
Parameters:
a - the long array to sort
fromIndex - the first index to sort (inclusive)
toIndex - the last index to sort (exclusive)
Throws:
IllegalArgumentException - if fromIndex > toIndex
ArrayIndexOutOfBoundsException - if fromIndex < 0 || toIndex > a.length

sort

public static void sort(short[] a)
Performs a stable sort on the elements, arranging them according to their natural order.
Parameters:
a - the short array to sort

sort

public static void sort(short[] a,
                        int fromIndex,
                        int toIndex)
Performs a stable sort on the elements, arranging them according to their natural order.
Parameters:
a - the short array to sort
fromIndex - the first index to sort (inclusive)
toIndex - the last index to sort (exclusive)
Throws:
IllegalArgumentException - if fromIndex > toIndex
ArrayIndexOutOfBoundsException - if fromIndex < 0 || toIndex > a.length

toString

public static String toString(boolean[] v)
Returns a String representation of the argument array. Returns "null" if a is null.
Parameters:
v - the array to represent
Returns:
a String representing this array
Since:
1.5

toString

public static String toString(byte[] v)
Returns a String representation of the argument array. Returns "null" if a is null.
Parameters:
v - the array to represent
Returns:
a String representing this array
Since:
1.5

toString

public static String toString(char[] v)
Returns a String representation of the argument array. Returns "null" if a is null.
Parameters:
v - the array to represent
Returns:
a String representing this array
Since:
1.5

toString

public static String toString(double[] v)
Returns a String representation of the argument array. Returns "null" if a is null.
Parameters:
v - the array to represent
Returns:
a String representing this array
Since:
1.5

toString

public static String toString(float[] v)
Returns a String representation of the argument array. Returns "null" if a is null.
Parameters:
v - the array to represent
Returns:
a String representing this array
Since:
1.5

toString

public static String toString(int[] v)
Returns a String representation of the argument array. Returns "null" if a is null.
Parameters:
v - the array to represent
Returns:
a String representing this array
Since:
1.5

toString

public static String toString(Object[] v)
Returns a String representation of the argument array. Returns "null" if a is null.
Parameters:
v - the array to represent
Returns:
a String representing this array
Since:
1.5

toString

public static String toString(long[] v)
Returns a String representation of the argument array. Returns "null" if a is null.
Parameters:
v - the array to represent
Returns:
a String representing this array
Since:
1.5

toString

public static String toString(short[] v)
Returns a String representation of the argument array. Returns "null" if a is null.
Parameters:
v - the array to represent
Returns:
a String representing this array
Since:
1.5

void sort

public static  void sort(T[] a,
                            T> c)
Sort an array of Objects according to a Comparator. The sort is guaranteed to be stable, that is, equal elements will not be reordered. The sort algorithm is a mergesort with the merge omitted if the last element of one half comes before the first element of the other half. This algorithm gives guaranteed O(n*log(n)) time, at the expense of making a copy of the array.
Parameters:
a - the array to be sorted
c - a Comparator to use in sorting the array; or null to indicate the elements' natural order
Throws:
ClassCastException - if any two elements are not mutually comparable by the Comparator provided
NullPointerException - if a null element is compared with natural ordering (only possible when c is null)

void sort

public static  void sort(T[] a,
                            int fromIndex,
                            int toIndex,
                            T> c)
Sort an array of Objects according to a Comparator. The sort is guaranteed to be stable, that is, equal elements will not be reordered. The sort algorithm is a mergesort with the merge omitted if the last element of one half comes before the first element of the other half. This algorithm gives guaranteed O(n*log(n)) time, at the expense of making a copy of the array.
Parameters:
a - the array to be sorted
fromIndex - the index of the first element to be sorted
toIndex - the index of the last element to be sorted plus one
c - a Comparator to use in sorting the array; or null to indicate the elements' natural order
Throws:
ClassCastException - if any two elements are not mutually comparable by the Comparator provided
ArrayIndexOutOfBoundsException - if fromIndex and toIndex are not in range.
IllegalArgumentException - if fromIndex > toIndex
NullPointerException - if a null element is compared with natural ordering (only possible when c is null)

Arrays.java -- Utility class with methods to operate on arrays Copyright (C) 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007, Free Software Foundation, Inc. This file is part of GNU Classpath. GNU Classpath is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2, or (at your option) any later version. GNU Classpath is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with GNU Classpath; see the file COPYING. If not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. Linking this library statically or dynamically with other modules is making a combined work based on this library. Thus, the terms and conditions of the GNU General Public License cover the whole combination. As a special exception, the copyright holders of this library give you permission to link this library with independent modules to produce an executable, regardless of the license terms of these independent modules, and to copy and distribute the resulting executable under terms of your choice, provided that you also meet, for each linked independent module, the terms and conditions of the license of that module. An independent module is a module which is not derived from or based on this library. If you modify this library, you may extend this exception to your version of the library, but you are not obligated to do so. If you do not wish to do so, delete this exception statement from your version.