All Packages Class Hierarchy This Package Previous Next Index
Class java.util.Arrays
java.lang.Object
|
+----java.util.Arrays
- public class Arrays
- extends Object
This class contains various methods for manipulating arrays (such as
sorting and searching). It also contains a static factory that allows
arrays to be viewed as Lists.
- Since:
- JDK1.2
- See Also:
- Comparable, Comparator
Arrays()
-
binarySearch(byte[], byte)
- Searches the specified array of bytes for the specified value using
the binary search algorithm.
binarySearch(char[], char)
- Searches the specified array of chars for the specified value using
the binary search algorithm.
binarySearch(double[], double)
- Searches the specified array of doubles for the specified value using
the binary search algorithm.
binarySearch(float[], float)
- Searches the specified array of floats for the specified value using
the binary search algorithm.
binarySearch(int[], int)
- Searches the specified array of ints for the specified value using
the binary search algorithm.
binarySearch(long[], long)
- Searches the specified array of longs for the specified value using
the binary search algorithm.
binarySearch(Object[], Object)
- Searches the specified array for the specified Object using the binary
search algorithm.
binarySearch(Object[], Object, Comparator)
- Searches the specified array for the specified Object using the binary
search algorithm.
binarySearch(short[], short)
- Searches the specified array of shorts for the specified value using
the binary search algorithm.
sort(byte[])
- Sorts the specified array of bytes into ascending numerical order.
sort(char[])
- Sorts the specified array of chars into ascending numerical order.
sort(double[])
- Sorts the specified array of doubles into ascending numerical order.
sort(float[])
- Sorts the specified array of floats into ascending numerical order.
sort(int[])
- Sorts the specified array of ints into ascending numerical order.
sort(long[])
- Sorts the specified array of longs into ascending numerical order.
sort(Object[])
- Sorts the specified array of objects into ascending order, according
to the natural comparison method of its elements.
sort(Object[], Comparator)
- Sorts the specified array according to the order induced by the
specified Comparator.
sort(short[])
- Sorts the specified array of shorts into ascending numerical order.
toList(Object[])
- Returns a fixed-size List backed by the specified array.
Arrays
public Arrays()
sort
public 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 offers n*log(n) performance on many data sets
that cause other quicksorts to degrade to quadratic performance.
sort
public 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 offers n*log(n) performance on many data sets
that cause other quicksorts to degrade to quadratic performance.
sort
public 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 algorithm offers n*log(n) performance on many data sets
that cause other quicksorts to degrade to quadratic performance.
sort
public 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 offers n*log(n) performance on many data sets
that cause other quicksorts to degrade to quadratic performance.
sort
public 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 offers n*log(n) performance on many data sets
that cause other quicksorts to degrade to quadratic performance.
sort
public static void sort(double[] a)
- Sorts the specified array of doubles 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 offers n*log(n) performance on many data sets
that cause other quicksorts to degrade to quadratic performance.
sort
public static void sort(float[] a)
- Sorts the specified array of floats 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 offers n*log(n) performance on many data sets
that cause other quicksorts to degrade to quadratic performance.
sort
public static void sort(Object[] a)
- Sorts the specified array of objects into ascending order, according
to the natural comparison method 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 throw a
typeMismatchException for any elements e1 and e2 in the array).
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 offers n*log(n) performance on many data sets
that cause other quicksorts to degrade to quadratic performance.
- Throws:
ClassCastException
- array contains elements that are not
mutually comparable (for example, Strings and
Integers).
- See Also:
- Comparable
sort
public static void sort(Object[] a,
Comparator c)
- Sorts the specified array according to the order induced by the
specified Comparator. All elements in the array must be mutually
comparable by the specified comparator (that is,
comparator.compare(e1, e2) must not throw a typeMismatchException for
any elements e1 and e2 in the array).
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 offers n*log(n) performance on many data sets
that cause other quicksorts to degrade to quadratic performance.
- Throws:
ClassCastException
- array contains elements that are not
mutually comparable with the specified Comparator.
- See Also:
- Comparator
binarySearch
public 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 must be
sorted (as by the sort method, above) prior to making this call. If
it is not sorted, the results are undefined: in particular, the call
may enter an infinite loop. If the array contains multiple elements
equal to the specified object, there is no guarantee which instance
will be found.
- Returns:
- index of the search key, if it is contained in the array;
otherwise, (-(insertion point) - 1). The insertion
point is defined as the the point at which the value would
be inserted into the array: the index of the first element
greater than the value, or a.length, if all elements in
the array are less than the specified value. Note that this
guarantees that the return value will be >= 0 if and only
if the object is found.
- See Also:
- sort
binarySearch
public 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 must be
sorted (as by the sort method, above) prior to making this call. If
it is not sorted, the results are undefined: in particular, the call
may enter an infinite loop. If the array contains multiple elements
equal to the specified object, there is no guarantee which instance
will be found.
- Returns:
- index of the search key, if it is contained in the array;
otherwise, (-(the "insertion point") - 1).
- See Also:
- sort
binarySearch
public 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 must be
sorted (as by the sort method, above) prior to making this call. If
it is not sorted, the results are undefined: in particular, the call
may enter an infinite loop. If the array contains multiple elements
equal to the specified object, there is no guarantee which instance
will be found.
- Returns:
- index of the search key, if it is contained in the array;
otherwise, (-(the "insertion point") - 1).
- See Also:
- sort
binarySearch
public 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 must be
sorted (as by the sort method, above) prior to making this call. If
it is not sorted, the results are undefined: in particular, the call
may enter an infinite loop. If the array contains multiple elements
equal to the specified object, there is no guarantee which instance
will be found.
- Returns:
- index of the search key, if it is contained in the array;
otherwise, (-(the "insertion point") - 1).
- See Also:
- sort
binarySearch
public 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 must be
sorted (as by the sort method, above) prior to making this call. If
it is not sorted, the results are undefined: in particular, the call
may enter an infinite loop. If the array contains multiple elements
equal to the specified object, there is no guarantee which instance
will be found.
- Returns:
- index of the search key, if it is contained in the array;
otherwise, (-(the "insertion point") - 1).
- See Also:
- sort
binarySearch
public 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 must be
sorted (as by the sort method, above) prior to making this call. If
it is not sorted, the results are undefined: in particular, the call
may enter an infinite loop. If the array contains multiple elements
equal to the specified object, there is no guarantee which instance
will be found.
- Returns:
- index of the search key, if it is contained in the array;
otherwise, (-(the "insertion point") - 1).
- See Also:
- sort
binarySearch
public 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 must be
sorted (as by the sort method, above) prior to making this call. If
it is not sorted, the results are undefined: in particular, the call
may enter an infinite loop. If the array contains multiple elements
equal to the specified object, there is no guarantee which instance
will be found.
- Returns:
- index of the search key, if it is contained in the array;
otherwise, (-(the "insertion point") - 1).
- See Also:
- sort
binarySearch
public 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 comparison method of its elements (as by
Sort(Object[]), above) prior to making this call. The array must
must be sorted (as by the sort method, above) prior to
making this call. If it is not sorted, the results are undefined: in
particular, the call may enter an infinite loop. If the array contains
multiple elements equal to the specified object, there is no guarantee
which instance will be found.
- Throws:
ClassCastException
- array contains elements that are not
mutually comparable (for example, Strings and
Integers), or the search key in not mutually comparable
with the elements of the array.
- See Also:
- Comparable, sort
binarySearch
public 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 Sort(Object[], Comparator),
above), prior to making this call. If it is not sorted, the results are
undefined: in particular, the call may enter an infinite loop. If the
array contains multiple elements equal to the specified object, there is
no guarantee which instance will be found.
- Throws:
ClassCastException
- array contains elements that are not
mutually comparable with the specified Comparator,
or the search key in not mutually comparable with the
elements of the array using this Comparator.
- See Also:
- Comparable, sort
toList
public static List toList(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.
- See Also:
- toArray
All Packages Class Hierarchy This Package Previous Next Index
Submit a bug or feature