Online demo
JavaDocPlus Demo | Show in full page mode
| Classic JavaDoc |
Class Arrays
java.lang.Object └ java.util.Arrays
public class Arrays
This class contains various methods for manipulating arrays (such as
sorting and searching). This class also contains a static factory
that allows arrays to be viewed as lists.
Author:The methods in this class all throw a NullPointerException if the specified array reference is null, except where noted.
The documentation for the methods contained in this class includes briefs description of the implementations. Such descriptions should be regarded as implementation notes, rather than parts of the specification. Implementors should feel free to substitute other algorithms, so long as the specification itself is adhered to. (For example, the algorithm used by sort(Object[]) does not have to be a mergesort, but it does have to be stable.)
This class is a member of the Java Collections Framework.
Josh BlochNeal Gafter
Version:1.59, 04/01/04
See Also:Comparable, Comparator
Since:1.2
Methods
static List | asList (Object a) | |
Returns a fixed-size list backed by the specified array. (Changes to the returned list "write through" to the array.) This method acts as bridge between array-based and collection-based APIs, in combination with Collection.toArray. The returned list is serializable and implements Ra ... more > |
static int | binarySearch (long a, long key) | |
Searches the specified array of longs for the specified value using the binary search algorithm. The array must be sorted (as by the sort method, above) prior to making this call. If it is not sorted, the results are undefined. If the array contains multiple elements with the specif ... more > |
static int | binarySearch (int a, int key) | |
Searches the specified array of ints for the specified value using the binary search algorithm. The array must be sorted (as by the sort method, above) prior to making this call. If it is not sorted, the results are undefined. If the array contains multiple elements with the specifi ... more > |
static int | binarySearch (short a, short key) | |
Searches the specified array of shorts for the specified value using the binary search algorithm. The array must be sorted (as by the sort method, above) prior to making this call. If it is not sorted, the results are undefined. If the array contains multiple elements with the speci ... more > |
static int | binarySearch (char a, char key) | |
Searches the specified array of chars for the specified value using the binary search algorithm. The array must be sorted (as by the sort method, above) prior to making this call. If it is not sorted, the results are undefined. If the array contains multiple elements with the specif ... more > |
static int | binarySearch (byte a, byte key) | |
Searches the specified array of bytes for the specified value using the binary search algorithm. The array must be sorted (as by the sort method, above) prior to making this call. If it is not sorted, the results are undefined. If the array contains multiple elements with the specif ... more > |
static int | binarySearch (double a, double key) | |
Searches the specified array of doubles for the specified value using the binary search algorithm. The array must be sorted (as by the sort method, above) prior to making this call. If it is not sorted, the results are undefined. If the array contains multiple elements with the spec ... more > |
static int | binarySearch (float a, float key) | |
Searches the specified array of floats for the specified value using the binary search algorithm. The array must be sorted (as by the sort method, above) prior to making this call. If it is not sorted, the results are undefined. If the array contains multiple elements with the speci ... more > |
static int | binarySearch (Object a, Object key) | |
Searches the specified array for the specified object using the binary search algorithm. The array must be sorted into ascending order according to the natural ordering of its elements (as by Sort(Object[]), above) prior to making this call. If it is not sorted, the results are undef ... more > |
static int | binarySearch (Object a, Object key, Comparator c) | |
Searches the specified array for the specified object using the binary search algorithm. The array must be sorted into ascending order according to the specified comparator (as by the Sort(Object[], Comparator) method, above), prior to making this call. If it is not sorted, the resul ... more > |
static boolean | deepEquals (Object a1, Object a2) | |
Returns true if the two specified arrays are deeply equal to one another. Unlike the |
static int | deepHashCode (Object a) | |
Returns a hash code based on the "deep contents" of the specified array. If the array contains other arrays as elements, the hash code is based on their contents and so on, ad infinitum. It is therefore unacceptable to invoke this method on an array that contains itself as an element, ... more > |
static String | deepToString (Object a) | |
Returns a string representation of the "deep contents" of the specified array. If the array contains other arrays as elements, the string representation contains their contents and so on. This method is designed for converting multidimensional arrays to strings. The string represen ... more > |
static boolean | equals (long a, long a2) | |
Returns true if the two specified arrays of longs are equal to one another. Two arrays are considered equal if both arrays contain the same number of elements, and all corresponding pairs of elements in the two arrays are equal. In other words, two arrays are equal if they contain th ... more > |
static boolean | equals (int a, int a2) | |
Returns true if the two specified arrays of ints are equal to one another. Two arrays are considered equal if both arrays contain the same number of elements, and all corresponding pairs of elements in the two arrays are equal. In other words, two arrays are equal if they contain the ... more > |
static boolean | equals (short a, short a2) | |
Returns true if the two specified arrays of shorts are equal to one another. Two arrays are considered equal if both arrays contain the same number of elements, and all corresponding pairs of elements in the two arrays are equal. In other words, two arrays are equal if they contain t ... more > |
static boolean | equals (char a, char a2) | |
Returns true if the two specified arrays of chars are equal to one another. Two arrays are considered equal if both arrays contain the same number of elements, and all corresponding pairs of elements in the two arrays are equal. In other words, two arrays are equal if they contain th ... more > |
static boolean | equals (byte a, byte a2) | |
Returns true if the two specified arrays of bytes are equal to one another. Two arrays are considered equal if both arrays contain the same number of elements, and all corresponding pairs of elements in the two arrays are equal. In other words, two arrays are equal if they contain th ... more > |
static boolean | equals (boolean a, boolean a2) | |
Returns true if the two specified arrays of booleans are equal to one another. Two arrays are considered equal if both arrays contain the same number of elements, and all corresponding pairs of elements in the two arrays are equal. In other words, two arrays are equal if they contain ... more > |
static boolean | equals (double a, double a2) | |
Returns true if the two specified arrays of doubles are equal to one another. Two arrays are considered equal if both arrays contain the same number of elements, and all corresponding pairs of elements in the two arrays are equal. In other words, two arrays are equal if they contain ... more > |
static boolean | equals (float a, float a2) | |
Returns true if the two specified arrays of floats are equal to one another. Two arrays are considered equal if both arrays contain the same number of elements, and all corresponding pairs of elements in the two arrays are equal. In other words, two arrays are equal if they contain t ... more > |
static boolean | equals (Object a, Object a2) | |
Returns true if the two specified arrays of Objects are equal to one another. The two arrays are considered equal if both arrays contain the same number of elements, and all corresponding pairs of elements in the two arrays are equal. Two objects e1 and e2 are considered equal if (e1 ... more > |
static void | fill (long a, long val) | |
Assigns the specified long value to each element of the specified array of longs. |
static void | fill (long a, int fromIndex, int toIndex, long val) | |
Assigns the specified long value to each element of the specified range of the specified array of longs. The range to be filled extends from index fromIndex, inclusive, to index toIndex, exclusive. (If fromIndex==toIndex, the range to be filled is empty.) |
static void | fill (int a, int val) | |
Assigns the specified int value to each element of the specified array of ints. |
static void | fill (int a, int fromIndex, int toIndex, int val) | |
Assigns the specified int value to each element of the specified range of the specified array of ints. The range to be filled extends from index fromIndex, inclusive, to index toIndex, exclusive. (If fromIndex==toIndex, the range to be filled is empty.) |
static void | fill (short a, short val) | |
Assigns the specified short value to each element of the specified array of shorts. |
static void | fill (short a, int fromIndex, int toIndex, short val) | |
Assigns the specified short value to each element of the specified range of the specified array of shorts. The range to be filled extends from index fromIndex, inclusive, to index toIndex, exclusive. (If fromIndex==toIndex, the range to be filled is empty.) |
static void | fill (char a, char val) | |
Assigns the specified char value to each element of the specified array of chars. |
static void | fill (char a, int fromIndex, int toIndex, char val) | |
Assigns the specified char value to each element of the specified range of the specified array of chars. The range to be filled extends from index fromIndex, inclusive, to index toIndex, exclusive. (If fromIndex==toIndex, the range to be filled is empty.) |
static void | fill (byte a, byte val) | |
Assigns the specified byte value to each element of the specified array of bytes. |
static void | fill (byte a, int fromIndex, int toIndex, byte val) | |
Assigns the specified byte value to each element of the specified range of the specified array of bytes. The range to be filled extends from index fromIndex, inclusive, to index toIndex, exclusive. (If fromIndex==toIndex, the range to be filled is empty.) |
static void | fill (boolean a, boolean val) | |
Assigns the specified boolean value to each element of the specified array of booleans. |
static void | fill (boolean a, int fromIndex, int toIndex, boolean val) | |
Assigns the specified boolean value to each element of the specified range of the specified array of booleans. The range to be filled extends from index fromIndex, inclusive, to index toIndex, exclusive. (If fromIndex==toIndex, the range to be filled is empty.) |
static void | fill (double a, double val) | |
Assigns the specified double value to each element of the specified array of doubles. |
static void | fill (double a, int fromIndex, int toIndex, double val) | |
Assigns the specified double value to each element of the specified range of the specified array of doubles. The range to be filled extends from index fromIndex, inclusive, to index toIndex, exclusive. (If fromIndex==toIndex, the range to be filled is empty.) |
static void | fill (float a, float val) | |
Assigns the specified float value to each element of the specified array of floats. |
static void | fill (float a, int fromIndex, int toIndex, float val) | |
Assigns the specified float value to each element of the specified range of the specified array of floats. The range to be filled extends from index fromIndex, inclusive, to index toIndex, exclusive. (If fromIndex==toIndex, the range to be filled is empty.) |
static void | fill (Object a, Object val) | |
Assigns the specified Object reference to each element of the specified array of Objects. |
static void | fill (Object a, int fromIndex, int toIndex, Object val) | |
Assigns the specified Object reference to each element of the specified range of the specified array of Objects. The range to be filled extends from index fromIndex, inclusive, to index toIndex, exclusive. (If fromIndex==toIndex, the range to be filled is empty.) |
static int | hashCode (long a) | |
Returns a hash code based on the contents of the specified array. For any two long arrays a and b such that Arrays.equals(a, b), it is also the case that Arrays.hashCode(a) == Arrays.hashCode(b). The value returned by this method is the same value that would be obtained by invoking ... more > |
static int | hashCode (int a) | |
Returns a hash code based on the contents of the specified array. For any two non-null int arrays a and b such that Arrays.equals(a, b), it is also the case that Arrays.hashCode(a) == Arrays.hashCode(b). The value returned by this method is the same value that would be obtained by i ... more > |
static int | hashCode (short a) | |
Returns a hash code based on the contents of the specified array. For any two short arrays a and b such that Arrays.equals(a, b), it is also the case that Arrays.hashCode(a) == Arrays.hashCode(b). The value returned by this method is the same value that would be obtained by invoking ... more > |
static int | hashCode (char a) | |
Returns a hash code based on the contents of the specified array. For any two char arrays a and b such that Arrays.equals(a, b), it is also the case that Arrays.hashCode(a) == Arrays.hashCode(b). The value returned by this method is the same value that would be obtained by invoking ... more > |
static int | hashCode (byte a) | |
Returns a hash code based on the contents of the specified array. For any two byte arrays a and b such that Arrays.equals(a, b), it is also the case that Arrays.hashCode(a) == Arrays.hashCode(b). The value returned by this method is the same value that would be obtained by invoking ... more > |
static int | hashCode (boolean a) | |
Returns a hash code based on the contents of the specified array. For any two boolean arrays a and b such that Arrays.equals(a, b), it is also the case that Arrays.hashCode(a) == Arrays.hashCode(b). The value returned by this method is the same value that would be obtained by invoki ... more > |
static int | hashCode (float a) | |
Returns a hash code based on the contents of the specified array. For any two float arrays a and b such that Arrays.equals(a, b), it is also the case that Arrays.hashCode(a) == Arrays.hashCode(b). The value returned by this method is the same value that would be obtained by invoking ... more > |
static int | hashCode (double a) | |
Returns a hash code based on the contents of the specified array. For any two double arrays a and b such that Arrays.equals(a, b), it is also the case that Arrays.hashCode(a) == Arrays.hashCode(b). The value returned by this method is the same value that would be obtained by invokin ... more > |
static int | hashCode (Object a) | |
Returns a hash code based on the contents of the specified array. If the array contains other arrays as elements, the hash code is based on their identities rather than their contents. It is therefore acceptable to invoke this method on an array that contains itself as an element, e ... more > |
static void | sort (long a) | |
Sorts the specified array of longs into ascending numerical order. The sorting algorithm 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 ... more > |
static void | sort (long a, int fromIndex, int toIndex) | |
Sorts the specified range of the specified array of longs into ascending numerical order. The range to be sorted extends from index fromIndex, inclusive, to index toIndex, exclusive. (If fromIndex==toIndex, the range to be sorted is empty.) The sorting algorithm is a tuned quicksort ... more > |
static void | sort (int a) | |
Sorts the specified array of ints into ascending numerical order. The sorting algorithm 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 ... more > |
static void | sort (int a, int fromIndex, int toIndex) | |
Sorts the specified range of the specified array of ints into ascending numerical order. The range to be sorted extends from index fromIndex, inclusive, to index toIndex, exclusive. (If fromIndex==toIndex, the range to be sorted is empty.) The sorting algorithm is a tuned quicksort, ... more > |
static void | sort (short a) | |
Sorts the specified array of shorts into ascending numerical order. The sorting algorithm 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 algorith ... more > |
static void | sort (short a, int fromIndex, int toIndex) | |
Sorts the specified range of the specified array of shorts into ascending numerical order. The range to be sorted extends from index fromIndex, inclusive, to index toIndex, exclusive. (If fromIndex==toIndex, the range to be sorted is empty.) The sorting algorithm is a tuned quicksor ... more > |
static void | sort (char a) | |
Sorts the specified array of chars into ascending numerical order. The sorting algorithm 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 ... more > |
static void | sort (char a, int fromIndex, int toIndex) | |
Sorts the specified range of the specified array of chars into ascending numerical order. The range to be sorted extends from index fromIndex, inclusive, to index toIndex, exclusive. (If fromIndex==toIndex, the range to be sorted is empty.) The sorting algorithm is a tuned quicksort ... more > |
static void | sort (byte a) | |
Sorts the specified array of bytes into ascending numerical order. The sorting algorithm 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 ... more > |
static void | sort (byte a, int fromIndex, int toIndex) | |
Sorts the specified range of the specified array of bytes into ascending numerical order. The range to be sorted extends from index fromIndex, inclusive, to index toIndex, exclusive. (If fromIndex==toIndex, the range to be sorted is empty.) The sorting algorithm is a tuned quicksort ... more > |
static void | sort (double a) | |
Sorts the specified array of doubles into ascending numerical order. The < relation does not provide a total order on all floating-point values; although they are distinct numbers -0.0 == 0.0 is true and a NaN value compares neither less than, greater than, nor equal to any floa ... more > |
static void | sort (double a, int fromIndex, int toIndex) | |
Sorts the specified range of the specified array of doubles into ascending numerical order. The range to be sorted extends from index fromIndex, inclusive, to index toIndex, exclusive. (If fromIndex==toIndex, the range to be sorted is empty.) The < relation does not provide a to ... more > |
static void | sort (float a) | |
Sorts the specified array of floats into ascending numerical order. The < relation does not provide a total order on all floating-point values; although they are distinct numbers -0.0f == 0.0f is true and a NaN value compares neither less than, greater than, nor equal to any flo ... more > |
static void | sort (float a, int fromIndex, int toIndex) | |
Sorts the specified range of the specified array of floats into ascending numerical order. The range to be sorted extends from index fromIndex, inclusive, to index toIndex, exclusive. (If fromIndex==toIndex, the range to be sorted is empty.) The < relation does not provide a tot ... more > |
static void | sort (Object a) | |
Sorts the specified array of objects into ascending order, according to the natural ordering of its elements. All elements in the array must implement the Comparable interface. Furthermore, all elements in the array must be mutually comparable (that is, e1.compareTo(e2) must not thro ... more > |
static void | sort (Object a, int fromIndex, int toIndex) | |
Sorts the specified range of the specified array of objects into ascending order, according to the natural ordering of its elements. The range to be sorted extends from index fromIndex, inclusive, to index toIndex, exclusive. (If fromIndex==toIndex, the range to be sorted is empty.) ... more > |
static void | sort (Object a, Comparator c) | |
Sorts the specified array of objects according to the order induced by the specified comparator. All elements in the array must be mutually comparable by the specified comparator (that is, c.compare(e1, e2) must not throw a ClassCastException for any elements e1 and e2 in the array). ... more > |
static void | sort (Object a, int fromIndex, int toIndex, Comparator c) | |
Sorts the specified range of the specified array of objects according to the order induced by the specified comparator. The range to be sorted extends from index fromIndex, inclusive, to index toIndex, exclusive. (If fromIndex==toIndex, the range to be sorted is empty.) All elements ... more > |
static String | toString (long a) | |
Returns a string representation of the contents of the specified array. The string representation consists of a list of the array's elements, enclosed in square brackets ("[]"). Adjacent elements are separated by the characters ", " (a comma followed by a space). Elements are convert ... more > |
static String | toString (int a) | |
Returns a string representation of the contents of the specified array. The string representation consists of a list of the array's elements, enclosed in square brackets ("[]"). Adjacent elements are separated by the characters ", " (a comma followed by a space). Elements are convert ... more > |
static String | toString (short a) | |
Returns a string representation of the contents of the specified array. The string representation consists of a list of the array's elements, enclosed in square brackets ("[]"). Adjacent elements are separated by the characters ", " (a comma followed by a space). Elements are convert ... more > |
static String | toString (char a) | |
Returns a string representation of the contents of the specified array. The string representation consists of a list of the array's elements, enclosed in square brackets ("[]"). Adjacent elements are separated by the characters ", " (a comma followed by a space). Elements are convert ... more > |
static String | toString (byte a) | |
Returns a string representation of the contents of the specified array. The string representation consists of a list of the array's elements, enclosed in square brackets ("[]"). Adjacent elements are separated by the characters ", " (a comma followed by a space). Elements are convert ... more > |
static String | toString (boolean a) | |
Returns a string representation of the contents of the specified array. The string representation consists of a list of the array's elements, enclosed in square brackets ("[]"). Adjacent elements are separated by the characters ", " (a comma followed by a space). Elements are convert ... more > |
static String | toString (float a) | |
Returns a string representation of the contents of the specified array. The string representation consists of a list of the array's elements, enclosed in square brackets ("[]"). Adjacent elements are separated by the characters ", " (a comma followed by a space). Elements are convert ... more > |
static String | toString (double a) | |
Returns a string representation of the contents of the specified array. The string representation consists of a list of the array's elements, enclosed in square brackets ("[]"). Adjacent elements are separated by the characters ", " (a comma followed by a space). Elements are convert ... more > |
static String | toString (Object a) | |
Returns a string representation of the contents of the specified array. If the array contains other arrays as elements, they are converted to strings by the Object#toString method inherited from Object, which describes their identities rather than their contents. The value returned ... more > |
Inherited methods
Community comments
Powered by JavaDocPlus