java.util
public class Arrays extends Object
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
UNKNOWN: updated to 1.4
Method Summary | |
---|---|
static <T> List<T> | asList(T... a)
Returns a list "view" of the specified array. |
static int | binarySearch(byte[] a, byte key)
Perform a binary search 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(short[] a, short key)
Perform a binary search of a short 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(long[] a, long key)
Perform a binary search of a long 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(double[] a, double key)
Perform a binary search of a double 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 <T> int | binarySearch(T[] a, T key, Comparator<? super T> c)
Perform a binary search of an Object array for a key, using a supplied
Comparator. |
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(short[] a1, short[] a2)
Compare two short arrays for equality.
|
static boolean | equals(int[] a1, int[] a2)
Compare two int arrays for equality.
|
static boolean | equals(long[] a1, long[] a2)
Compare two long arrays for equality.
|
static boolean | equals(float[] a1, float[] a2)
Compare two float arrays for equality.
|
static boolean | equals(double[] a1, double[] a2)
Compare two double arrays for equality.
|
static boolean | equals(Object[] a1, Object[] a2)
Compare two Object 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(short[] a, short val)
Fill an array with a short 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(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(long[] a, long val)
Fill an array with a long 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(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(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(Object[] a, Object val)
Fill an array with an Object value.
|
static void | fill(Object[] a, int fromIndex, int toIndex, Object val)
Fill a range of an array with an Object value.
|
static int | hashCode(long[] v)
Returns the hashcode of an array of long numbers. |
static int | hashCode(int[] v)
Returns the hashcode of an array of integer numbers. |
static int | hashCode(short[] v)
Returns the hashcode of an array of short numbers. |
static int | hashCode(char[] v)
Returns the hashcode of an array of characters. |
static int | hashCode(byte[] v)
Returns the hashcode of an array of bytes. |
static int | hashCode(boolean[] v)
Returns the hashcode of an array of booleans. |
static int | hashCode(float[] v)
Returns the hashcode of an array of floats. |
static int | hashCode(double[] v)
Returns the hashcode of an array of doubles. |
static int | hashCode(Object[] v)
Returns the hashcode of an array of objects. |
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(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 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(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(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(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(Object[] a)
Sort an array of Objects according to their natural ordering. |
static <T> void | sort(T[] a, Comparator<? super T> c)
Sort an array of Objects according to a Comparator. |
static void | sort(Object[] a, int fromIndex, int toIndex)
Sort an array of Objects according to their natural ordering. |
static <T> void | sort(T[] a, int fromIndex, int toIndex, Comparator<? super T> c)
Sort an array of Objects according to a Comparator. |
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(short[] 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(long[] 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(double[] v)
Returns a String representation of the argument array. |
static String | toString(Object[] v)
Returns a String representation of the argument array. |
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 ArrayList
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.
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.
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.
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.
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.
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.
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.
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
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)
Since: 1.5
Since: 1.5
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 < a1.length, a1[i] == a2[i]
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 < a1.length, a1[i] == a2[i]
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 < a1.length, a1[i] == a2[i]
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 < a1.length, a1[i] == a2[i]
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 < a1.length, a1[i] == a2[i]
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 < a1.length, a1[i] == a2[i]
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 < a1.length, a1[i] == a2[i]
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 < a1.length, a1[i] == a2[i]
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 < a.length, a1[i] == null ? a2[i] == null : a1[i].equals(a2[i]).
Parameters: a the array to fill val the value to fill it with
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
Parameters: a the array to fill val the value to fill it with
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
Parameters: a the array to fill val the value to fill it with
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
Parameters: a the array to fill val the value to fill it with
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
Parameters: a the array to fill val the value to fill it with
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
Parameters: a the array to fill val the value to fill it with
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
Parameters: a the array to fill val the value to fill it with
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
Parameters: a the array to fill val the value to fill it with
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
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.
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
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
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
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
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
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
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
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
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
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
Parameters: a the byte array to sort
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
Parameters: a the char array to sort
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
Parameters: a the short array to sort
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
Parameters: a the int array to sort
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
Parameters: a the long array to sort
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
Parameters: a the float array to sort
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
Parameters: a the double array to sort
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
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
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)
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
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)
a
is null.Parameters: v the array to represent
Returns: a String representing this array
Since: 1.5
a
is null.Parameters: v the array to represent
Returns: a String representing this array
Since: 1.5
a
is null.Parameters: v the array to represent
Returns: a String representing this array
Since: 1.5
a
is null.Parameters: v the array to represent
Returns: a String representing this array
Since: 1.5
a
is null.Parameters: v the array to represent
Returns: a String representing this array
Since: 1.5
a
is null.Parameters: v the array to represent
Returns: a String representing this array
Since: 1.5
a
is null.Parameters: v the array to represent
Returns: a String representing this array
Since: 1.5
a
is null.Parameters: v the array to represent
Returns: a String representing this array
Since: 1.5
a
is null.Parameters: v the array to represent
Returns: a String representing this array
Since: 1.5