[all packages] [package java.util] [class hierarchy] [index]

public class java.util.Arrays

(source file: Arrays.java)
java.lang.Object
   |
   +----java.util.Arrays

The pure class interface.
public class Arrays
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.

See also:
Comparable, Comparator

Constuctor Index

O Arrays()

Methods

O binarySearch(short[], short)
Searches the specified array of shorts for the specified value using the binary search
O binarySearch(int[], int)
Searches the specified array of ints for the specified value using the binary search
O binarySearch(double[], double)
Searches the specified array of doubles for the specified value using the binary search
O binarySearch(A[], A, Comparator<A>)
Searches the specified array for the specified Object using the binary search algorithm
O binarySearch(A[], A)
Searches the specified array for the specified Object using the binary search algorithm
O binarySearch(float[], float)
Searches the specified array of floats for the specified value using the binary search
O binarySearch(byte[], byte)
Searches the specified array of bytes for the specified value using the binary search
O binarySearch(char[], char)
Searches the specified array of chars for the specified value using the binary search
O binarySearch(long[], long)
Searches the specified array of longs for the specified value using the binary search
O equals(short[], Object)
Returns true if the the specified array of short is equal to the given object
O equals(byte[], Object)
Returns true if the the specified array of byte is equal to the given object
O equals(double[], Object)
Returns true if the the specified array of double is equal to the given object
O equals(A[], Object)
Returns true if the the specified array of Object is equal to the given object
O equals(float[], Object)
Returns true if the the specified array of float is equal to the given object
O equals(boolean[], Object)
Returns true if the the specified array of boolean is equal to the given object
O equals(char[], Object)
Returns true if the the specified array of char is equal to the given object
O equals(int[], Object)
Returns true if the the specified array of int is equal to the given object
O equals(long[], Object)
Returns true if the the specified array of long is equal to the given object
O fill(char[], char)
Sets each element of the specified array of chars with the specified char value.
O fill(boolean[], boolean)
Sets each element of the specified array of booleans with the specified boolean value.
O fill(float[], float)
Sets each element of the specified array of floats with the specified float value.
O fill(A[], A)
Sets each element of the specified array of Objects with the specified Object value.
O fill(double[], double)
Sets each element of the specified array of doubles with the specified double value.
O fill(byte[], byte)
Sets each element of the specified array of bytes with the specified byte value.
O fill(int[], int)
Sets each element of the specified array of ints with the specified int value.
O fill(short[], short)
Sets each element of the specified array of shorts with the specified short value.
O fill(long[], long)
Sets each element of the specified array of longs with the specified long value.
O sort(short[])
Sorts the specified array of shorts into ascending numerical order. The sorting algorithm
O sort(byte[])
Sorts the specified array of bytes into ascending numerical order. The sorting algorithm
O sort(float[])
Sorts the specified array of floats into ascending numerical order. The sorting algorithm
O sort(A[], Comparator<A>)
Sorts the specified array of objects according to the order induced by the specified
O sort(A[])
Sorts the specified array of objects into ascending order, according to the natural
O sort(double[])
Sorts the specified array of doubles into ascending numerical order. The sorting
O sort(char[])
Sorts the specified array of chars into ascending numerical order. The sorting algorithm
O sort(int[])
Sorts the specified array of ints into ascending numerical order. The sorting algorithm
O sort(long[])
Sorts the specified array of longs into ascending numerical order. The sorting algorithm
O toList(A[])
Returns a fixed-size List backed by the specified array

Inner Class Index

ArrayList<A>

Constructors

O Arrays
public Arrays();

Methods

O 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.

Parameters:
a - the array to be sorted.

O 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.

Parameters:
a - the array to be sorted.

O 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.

Parameters:
a - the array to be sorted.

O 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.

Parameters:
a - the array to be sorted.

O 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.

Parameters:
a - the array to be sorted.

O 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.

Parameters:
a - the array to be sorted.

O 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.

Parameters:
a - the array to be sorted.

O sort

public static <A> void sort(A[] 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).

This sort is guaranteed to be stable: equal elements will not be reordered as a result of the sort.

The sorting algorithm is a modified mergesort (in which the merge is omitted if the highest element in the low sublist is less than the lowest element in the high sublist). This algorithm offers guaranteed n*log(n) performance, and can approach linear performance on nearly sorted lists.

Parameters:
a - the array to be sorted.
Throws:
ClassCastException -array contains elements that are not mutually comparable (for example, Strings and Integers).
See also:
Comparable

O sort

public static <A> void sort(A[] a,
                            Comparator<A> 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, comparator.compare(e1, e2) must not throw a typeMismatchException for any elements e1 and e2 in the array).

This sort is guaranteed to be stable: equal elements will not be reordered as a result of the sort.

The sorting algorithm is a modified mergesort (in which the merge is omitted if the highest element in the low sublist is less than the lowest element in the high sublist). This algorithm offers guaranteed n*log(n) performance, and can approach linear performance on nearly sorted lists.

Parameters:
a - the array to be sorted.
c - the Comparator to determine the order of the array.
Throws:
ClassCastException -array contains elements that are not mutually comparable with the specified Comparator.
See also:
Comparator

O 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.

Parameters:
a - the array to be searched.
key - the value to be searched for.
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(long[])

O 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.

Parameters:
a - the array to be searched.
key - the value to be searched for.
Returns:
index of the search key, if it is contained in the array; otherwise, (-(the "insertion point") - 1).
See also:
sort(int[])

O 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.

Parameters:
a - the array to be searched.
key - the value to be searched for.
Returns:
index of the search key, if it is contained in the array; otherwise, (-(the "insertion point") - 1).
See also:
sort(short[])

O 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.

Parameters:
a - the array to be searched.
key - the value to be searched for.
Returns:
index of the search key, if it is contained in the array; otherwise, (-(the "insertion point") - 1).
See also:
sort(char[])

O 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.

Parameters:
a - the array to be searched.
key - the value to be searched for.
Returns:
index of the search key, if it is contained in the array; otherwise, (-(the "insertion point") - 1).
See also:
sort(byte[])

O 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.

Parameters:
a - the array to be searched.
key - the value to be searched for.
Returns:
index of the search key, if it is contained in the array; otherwise, (-(the "insertion point") - 1).
See also:
sort(double[])

O 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.

Parameters:
a - the array to be searched.
key - the value to be searched for.
Returns:
index of the search key, if it is contained in the array; otherwise, (-(the "insertion point") - 1).
See also:
sort(float[])

O binarySearch

public static <A> int binarySearch(A[] a,
                                   A 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.

Parameters:
a - the array to be searched.
key - the value to be searched for.
Returns:
index of the search key, if it is contained in the array; otherwise, (-(the "insertion point") - 1).
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(Object[])

O binarySearch

public static <A> int binarySearch(A[] a,
                                   A key,
                                   Comparator<A> 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.

Parameters:
a - the array to be searched.
key - the value to be searched for.
c - the Comparator to determine the order of the array.
Returns:
index of the search key, if it is contained in the array; otherwise, (-(the "insertion point") - 1).
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(Object[], Comparator)

O equals

public static boolean equals(long[] a,
                             Object o);
Returns true if the the specified array of long is equal to the given object. The array and the object are considered equal if the object is of type long[], both arrays contain the same number of elements, and all corresponding pairs of elements in the two arrays are equal. In other words, the two arrays are equal if they contain the same elements in the same order. Also, the array is considered equal to the object if both are null.

Parameters:
a - the array to be tested for equality.
o - the object to be tested for equality.
Returns:
true if the array and the object are equal.

O equals

public static boolean equals(int[] a,
                             Object o);
Returns true if the the specified array of int is equal to the given object. The array and the object are considered equal if the object is of type int[], both arrays contain the same number of elements, and all corresponding pairs of elements in the two arrays are equal. In other words, the two arrays are equal if they contain the same elements in the same order. Also, the array is considered equal to the object if both are null.

Parameters:
a - the array to be tested for equality.
o - the object to be tested for equality.
Returns:
true if the array and the object are equal.

O equals

public static boolean equals(short[] a,
                             Object o);
Returns true if the the specified array of short is equal to the given object. The array and the object are considered equal if the object is of type short[], both arrays contain the same number of elements, and all corresponding pairs of elements in the two arrays are equal. In other words, the two arrays are equal if they contain the same elements in the same order. Also, the array is considered equal to the object if both are null.

Parameters:
a - the array to be tested for equality.
o - the object to be tested for equality.
Returns:
true if the array and the object are equal.

O equals

public static boolean equals(char[] a,
                             Object o);
Returns true if the the specified array of char is equal to the given object. The array and the object are considered equal if the object is of type char[], both arrays contain the same number of elements, and all corresponding pairs of elements in the two arrays are equal. In other words, the two arrays are equal if they contain the same elements in the same order. Also, the array is considered equal to the object if both are null.

Parameters:
a - the array to be tested for equality.
o - the object to be tested for equality.
Returns:
true if the array and the object are equal.

O equals

public static boolean equals(byte[] a,
                             Object o);
Returns true if the the specified array of byte is equal to the given object. The array and the object are considered equal if the object is of type byte[], both arrays contain the same number of elements, and all corresponding pairs of elements in the two arrays are equal. In other words, the two arrays are equal if they contain the same elements in the same order. Also, the array is considered equal to the object if both are null.

Parameters:
a - the array to be tested for equality.
o - the object to be tested for equality.
Returns:
true if the array and the object are equal.

O equals

public static boolean equals(boolean[] a,
                             Object o);
Returns true if the the specified array of boolean is equal to the given object. The array and the object are considered equal if the object is of type boolean[], both arrays contain the same number of elements, and all corresponding pairs of elements in the two arrays are equal. In other words, the two arrays are equal if they contain the same elements in the same order. Also, the array is considered equal to the object if both are null.

Parameters:
a - the array to be tested for equality.
o - the object to be tested for equality.
Returns:
true if the array and the object are equal.

O equals

public static boolean equals(double[] a,
                             Object o);
Returns true if the the specified array of double is equal to the given object. The array and the object are considered equal if the object is of type double[], both arrays contain the same number of elements, and all corresponding pairs of elements in the two arrays are equal. In other words, the two arrays are equal if they contain the same elements in the same order. Also, the array is considered equal to the object if both are null.

Parameters:
a - the array to be tested for equality.
o - the object to be tested for equality.
Returns:
true if the array and the object are equal.

O equals

public static boolean equals(float[] a,
                             Object o);
Returns true if the the specified array of float is equal to the given object. The array and the object are considered equal if the object is of type float[], both arrays contain the same number of elements, and all corresponding pairs of elements in the two arrays are equal. In other words, the two arrays are equal if they contain the same elements in the same order. Also, the array is considered equal to the object if both are null.

Parameters:
a - the array to be tested for equality.
o - the object to be tested for equality.
Returns:
true if the array and the object are equal.

O equals

public static <A> boolean equals(A[] a,
                                 Object o);
Returns true if the the specified array of Object is equal to the given object. The array and the object are considered equal if the object is of type Object[], both arrays contain the same number of elements, and all corresponding pairs of elements in the two arrays are equal. In other words, the two arrays are equal if they contain the same elements in the same order. Also, the array is considered equal to the object if both are null.

Parameters:
a - the array to be tested for equality.
o - the object to be tested for equality.
Returns:
true if the array and the object are equal.

O fill

public static void fill(long[] a,
                        long val);
Sets each element of the specified array of longs with the specified long value.

Parameters:
a - the array to be filled.
val - the value to be stored in all elements of the array.

O fill

public static void fill(int[] a,
                        int val);
Sets each element of the specified array of ints with the specified int value.

Parameters:
a - the array to be filled.
val - the value to be stored in all elements of the array.

O fill

public static void fill(short[] a,
                        short val);
Sets each element of the specified array of shorts with the specified short value.

Parameters:
a - the array to be filled.
val - the value to be stored in all elements of the array.

O fill

public static void fill(char[] a,
                        char val);
Sets each element of the specified array of chars with the specified char value.

Parameters:
a - the array to be filled.
val - the value to be stored in all elements of the array.

O fill

public static void fill(byte[] a,
                        byte val);
Sets each element of the specified array of bytes with the specified byte value.

Parameters:
a - the array to be filled.
val - the value to be stored in all elements of the array.

O fill

public static void fill(boolean[] a,
                        boolean val);
Sets each element of the specified array of booleans with the specified boolean value.

Parameters:
a - the array to be filled.
val - the value to be stored in all elements of the array.

O fill

public static void fill(double[] a,
                        double val);
Sets each element of the specified array of doubles with the specified double value.

Parameters:
a - the array to be filled.
val - the value to be stored in all elements of the array.

O fill

public static void fill(float[] a,
                        float val);
Sets each element of the specified array of floats with the specified float value.

Parameters:
a - the array to be filled.
val - the value to be stored in all elements of the array.

O fill

public static <A> void fill(A[] a,
                            A val);
Sets each element of the specified array of Objects with the specified Object value.

Parameters:
a - the array to be filled.
val - the value to be stored in all elements of the array.

O toList

public static <A> List<A> toList(A[] 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.

Parameters:
a - the array by which the List will be backed.
Returns:
a List view of the specified array.
See also:
toArray()

Inner Classes

private static class ArrayList<A>
private static class ArrayList<A>
  extends AbstractList<A>
  implements Cloneable


[all packages] [package java.util] [class hierarchy] [index]
java.util.Arrays.html