Arrays.Sort Method

Definition

Overloads

Sort(Object[], Int32, Int32, IComparator)

Sorts the specified range of the specified array of objects according to the order induced by the specified comparator.

Sort(Byte[], Int32, Int32)

Sorts the specified range of the array into ascending order.

Sort(Single[], Int32, Int32)

Sorts the specified range of the array into ascending order.

Sort(Int64[], Int32, Int32)

Sorts the specified range of the array into ascending order.

Sort(Int32[], Int32, Int32)

Sorts the specified range of the array into ascending order.

Sort(Int16[], Int32, Int32)

Sorts the specified range of the array into ascending order.

Sort(Double[], Int32, Int32)

Sorts the specified range of the array into ascending order.

Sort(Char[], Int32, Int32)

Sorts the specified range of the array into ascending order.

Sort(Object[], Int32, Int32)

Sorts the specified range of the specified array of objects into ascending order, according to the Comparable natural ordering of its elements.

Sort(Single[])

Sorts the specified array into ascending numerical order.

Sort(Int64[])

Sorts the specified array into ascending numerical order.

Sort(Int32[])

Sorts the specified array into ascending numerical order.

Sort(Int16[])

Sorts the specified array into ascending numerical order.

Sort(Double[])

Sorts the specified array into ascending numerical order.

Sort(Char[])

Sorts the specified array into ascending numerical order.

Sort(Byte[])

Sorts the specified array into ascending numerical order.

Sort(Object[])

Sorts the specified array of objects into ascending order, according to the Comparable natural ordering of its elements.

Sort(Object[], IComparator)

Sorts the specified array of objects according to the order induced by the specified comparator.

Sort(Object[], Int32, Int32, IComparator)

Sorts the specified range of the specified array of objects according to the order induced by the specified comparator.

[Android.Runtime.Register("sort", "([Ljava/lang/Object;IILjava/util/Comparator;)V", "")]
[Java.Interop.JavaTypeParameters(new System.String[] { "T" })]
public static void Sort (Java.Lang.Object[] a, int fromIndex, int toIndex, Java.Util.IComparator? c);
[<Android.Runtime.Register("sort", "([Ljava/lang/Object;IILjava/util/Comparator;)V", "")>]
[<Java.Interop.JavaTypeParameters(new System.String[] { "T" })>]
static member Sort : Java.Lang.Object[] * int * int * Java.Util.IComparator -> unit

Parameters

a
Object[]

the array to be sorted

fromIndex
Int32

the index of the first element (inclusive) to be sorted

toIndex
Int32

the index of the last element (exclusive) to be sorted

c
IComparator

the comparator to determine the order of the array. A null value indicates that the elements' Comparable natural ordering should be used.

Attributes

Remarks

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 in the range 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 range).

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

Implementation note: This implementation is a stable, adaptive, iterative mergesort that requires far fewer than n lg(n) comparisons when the input array is partially sorted, while offering the performance of a traditional mergesort when the input array is randomly ordered. If the input array is nearly sorted, the implementation requires approximately n comparisons. Temporary storage requirements vary from a small constant for nearly sorted input arrays to n/2 object references for randomly ordered input arrays.

The implementation takes equal advantage of ascending and descending order in its input array, and can take advantage of ascending and descending order in different parts of the same input array. It is well-suited to merging two or more sorted arrays: simply concatenate the arrays and sort the resulting array.

The implementation was adapted from Tim Peters's list sort for Python ( TimSort). It uses techniques from Peter McIlroy's "Optimistic Sorting and Information Theoretic Complexity", in Proceedings of the Fourth Annual ACM-SIAM Symposium on Discrete Algorithms, pp 467-474, January 1993.

Java documentation for java.util.Arrays.sort(T[], int, int, java.util.Comparator<? super T>).

Portions of this page are modifications based on work created and shared by the Android Open Source Project and used according to terms described in the Creative Commons 2.5 Attribution License.

Applies to

Sort(Byte[], Int32, Int32)

Sorts the specified range of the array into ascending order.

[Android.Runtime.Register("sort", "([BII)V", "")]
public static void Sort (byte[] a, int fromIndex, int toIndex);
[<Android.Runtime.Register("sort", "([BII)V", "")>]
static member Sort : byte[] * int * int -> unit

Parameters

a
Byte[]

the array to be sorted

fromIndex
Int32

the index of the first element, inclusive, to be sorted

toIndex
Int32

the index of the last element, exclusive, to be sorted

Attributes

Exceptions

if start > end.

if start or end > array.length.

Remarks

Sorts the specified range of the array into ascending order. The range to be sorted extends from the index fromIndex, inclusive, to the index toIndex, exclusive. If fromIndex == toIndex, the range to be sorted is empty.

Java documentation for java.util.Arrays.sort(byte[], int, int).

Portions of this page are modifications based on work created and shared by the Android Open Source Project and used according to terms described in the Creative Commons 2.5 Attribution License.

Applies to

Sort(Single[], Int32, Int32)

Sorts the specified range of the array into ascending order.

[Android.Runtime.Register("sort", "([FII)V", "")]
public static void Sort (float[] a, int fromIndex, int toIndex);
[<Android.Runtime.Register("sort", "([FII)V", "")>]
static member Sort : single[] * int * int -> unit

Parameters

a
Single[]

the array to be sorted

fromIndex
Int32

the index of the first element, inclusive, to be sorted

toIndex
Int32

the index of the last element, exclusive, to be sorted

Attributes

Exceptions

if start > end.

if start or end > array.length.

Remarks

Sorts the specified range of the array into ascending order. The range to be sorted extends from the index fromIndex, inclusive, to the index toIndex, exclusive. If fromIndex == toIndex, the range to be sorted is empty.

The < relation does not provide a total order on all float values: -0.0f == 0.0f is true and a Float.NaN value compares neither less than, greater than, nor equal to any value, even itself. This method uses the total order imposed by the method Float#compareTo: -0.0f is treated as less than value 0.0f and Float.NaN is considered greater than any other value and all Float.NaN values are considered equal.

Java documentation for java.util.Arrays.sort(float[], int, int).

Portions of this page are modifications based on work created and shared by the Android Open Source Project and used according to terms described in the Creative Commons 2.5 Attribution License.

See also

Applies to

Sort(Int64[], Int32, Int32)

Sorts the specified range of the array into ascending order.

[Android.Runtime.Register("sort", "([JII)V", "")]
public static void Sort (long[] a, int fromIndex, int toIndex);
[<Android.Runtime.Register("sort", "([JII)V", "")>]
static member Sort : int64[] * int * int -> unit

Parameters

a
Int64[]

the array to be sorted

fromIndex
Int32

the index of the first element, inclusive, to be sorted

toIndex
Int32

the index of the last element, exclusive, to be sorted

Attributes

Exceptions

if start > end.

if start or end > array.length.

Remarks

Sorts the specified range of the array into ascending order. The range to be sorted extends from the index fromIndex, inclusive, to the index toIndex, exclusive. If fromIndex == toIndex, the range to be sorted is empty.

Java documentation for java.util.Arrays.sort(long[], int, int).

Portions of this page are modifications based on work created and shared by the Android Open Source Project and used according to terms described in the Creative Commons 2.5 Attribution License.

Applies to

Sort(Int32[], Int32, Int32)

Sorts the specified range of the array into ascending order.

[Android.Runtime.Register("sort", "([III)V", "")]
public static void Sort (int[] a, int fromIndex, int toIndex);
[<Android.Runtime.Register("sort", "([III)V", "")>]
static member Sort : int[] * int * int -> unit

Parameters

a
Int32[]

the array to be sorted

fromIndex
Int32

the index of the first element, inclusive, to be sorted

toIndex
Int32

the index of the last element, exclusive, to be sorted

Attributes

Exceptions

if start > end.

if start or end > array.length.

Remarks

Sorts the specified range of the array into ascending order. The range to be sorted extends from the index fromIndex, inclusive, to the index toIndex, exclusive. If fromIndex == toIndex, the range to be sorted is empty.

Java documentation for java.util.Arrays.sort(int[], int, int).

Portions of this page are modifications based on work created and shared by the Android Open Source Project and used according to terms described in the Creative Commons 2.5 Attribution License.

Applies to

Sort(Int16[], Int32, Int32)

Sorts the specified range of the array into ascending order.

[Android.Runtime.Register("sort", "([SII)V", "")]
public static void Sort (short[] a, int fromIndex, int toIndex);
[<Android.Runtime.Register("sort", "([SII)V", "")>]
static member Sort : int16[] * int * int -> unit

Parameters

a
Int16[]

the array to be sorted

fromIndex
Int32

the index of the first element, inclusive, to be sorted

toIndex
Int32

the index of the last element, exclusive, to be sorted

Attributes

Exceptions

if start > end.

if start or end > array.length.

Remarks

Sorts the specified range of the array into ascending order. The range to be sorted extends from the index fromIndex, inclusive, to the index toIndex, exclusive. If fromIndex == toIndex, the range to be sorted is empty.

Java documentation for java.util.Arrays.sort(short[], int, int).

Portions of this page are modifications based on work created and shared by the Android Open Source Project and used according to terms described in the Creative Commons 2.5 Attribution License.

Applies to

Sort(Double[], Int32, Int32)

Sorts the specified range of the array into ascending order.

[Android.Runtime.Register("sort", "([DII)V", "")]
public static void Sort (double[] a, int fromIndex, int toIndex);
[<Android.Runtime.Register("sort", "([DII)V", "")>]
static member Sort : double[] * int * int -> unit

Parameters

a
Double[]

the array to be sorted

fromIndex
Int32

the index of the first element, inclusive, to be sorted

toIndex
Int32

the index of the last element, exclusive, to be sorted

Attributes

Exceptions

if start > end.

if start or end > array.length.

Remarks

Sorts the specified range of the array into ascending order. The range to be sorted extends from the index fromIndex, inclusive, to the index toIndex, exclusive. If fromIndex == toIndex, the range to be sorted is empty.

The < relation does not provide a total order on all double values: -0.0d == 0.0d is true and a Double.NaN value compares neither less than, greater than, nor equal to any value, even itself. This method uses the total order imposed by the method Double#compareTo: -0.0d is treated as less than value 0.0d and Double.NaN is considered greater than any other value and all Double.NaN values are considered equal.

Java documentation for java.util.Arrays.sort(double[], int, int).

Portions of this page are modifications based on work created and shared by the Android Open Source Project and used according to terms described in the Creative Commons 2.5 Attribution License.

See also

Applies to

Sort(Char[], Int32, Int32)

Sorts the specified range of the array into ascending order.

[Android.Runtime.Register("sort", "([CII)V", "")]
public static void Sort (char[] a, int fromIndex, int toIndex);
[<Android.Runtime.Register("sort", "([CII)V", "")>]
static member Sort : char[] * int * int -> unit

Parameters

a
Char[]

the array to be sorted

fromIndex
Int32

the index of the first element, inclusive, to be sorted

toIndex
Int32

the index of the last element, exclusive, to be sorted

Attributes

Exceptions

if start > end.

if start or end > array.length.

Remarks

Sorts the specified range of the array into ascending order. The range to be sorted extends from the index fromIndex, inclusive, to the index toIndex, exclusive. If fromIndex == toIndex, the range to be sorted is empty.

Java documentation for java.util.Arrays.sort(char[], int, int).

Portions of this page are modifications based on work created and shared by the Android Open Source Project and used according to terms described in the Creative Commons 2.5 Attribution License.

Applies to

Sort(Object[], Int32, Int32)

Sorts the specified range of the specified array of objects into ascending order, according to the Comparable natural ordering of its elements.

[Android.Runtime.Register("sort", "([Ljava/lang/Object;II)V", "")]
public static void Sort (Java.Lang.Object[] a, int fromIndex, int toIndex);
[<Android.Runtime.Register("sort", "([Ljava/lang/Object;II)V", "")>]
static member Sort : Java.Lang.Object[] * int * int -> unit

Parameters

a
Object[]

the array to be sorted

fromIndex
Int32

the index of the first element (inclusive) to be sorted

toIndex
Int32

the index of the last element (exclusive) to be sorted

Attributes

Exceptions

if any element does not implement Comparable, or if compareTo throws for any pair of elements.

if start > end.

if start or end > array.length.

Remarks

Sorts the specified range of the specified array of objects into ascending order, according to the Comparable 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.) All elements in this range must implement the Comparable interface. Furthermore, all elements in this range must be mutually comparable (that is, e1.compareTo(e2) must not throw a ClassCastException 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.

Implementation note: This implementation is a stable, adaptive, iterative mergesort that requires far fewer than n lg(n) comparisons when the input array is partially sorted, while offering the performance of a traditional mergesort when the input array is randomly ordered. If the input array is nearly sorted, the implementation requires approximately n comparisons. Temporary storage requirements vary from a small constant for nearly sorted input arrays to n/2 object references for randomly ordered input arrays.

The implementation takes equal advantage of ascending and descending order in its input array, and can take advantage of ascending and descending order in different parts of the same input array. It is well-suited to merging two or more sorted arrays: simply concatenate the arrays and sort the resulting array.

The implementation was adapted from Tim Peters's list sort for Python ( TimSort). It uses techniques from Peter McIlroy's "Optimistic Sorting and Information Theoretic Complexity", in Proceedings of the Fourth Annual ACM-SIAM Symposium on Discrete Algorithms, pp 467-474, January 1993.

Java documentation for java.util.Arrays.sort(java.lang.Object[], int, int).

Portions of this page are modifications based on work created and shared by the Android Open Source Project and used according to terms described in the Creative Commons 2.5 Attribution License.

Applies to

Sort(Single[])

Sorts the specified array into ascending numerical order.

[Android.Runtime.Register("sort", "([F)V", "")]
public static void Sort (float[] a);
[<Android.Runtime.Register("sort", "([F)V", "")>]
static member Sort : single[] -> unit

Parameters

a
Single[]

the array to be sorted

Attributes

Remarks

Sorts the specified array into ascending numerical order.

The < relation does not provide a total order on all float values: -0.0f == 0.0f is true and a Float.NaN value compares neither less than, greater than, nor equal to any value, even itself. This method uses the total order imposed by the method Float#compareTo: -0.0f is treated as less than value 0.0f and Float.NaN is considered greater than any other value and all Float.NaN values are considered equal.

Java documentation for java.util.Arrays.sort(float[]).

Portions of this page are modifications based on work created and shared by the Android Open Source Project and used according to terms described in the Creative Commons 2.5 Attribution License.

See also

  • <xref:Java.Util.Arrays.Sort(System.Single%5b%5d%2c+System.Int32%2c+System.Int32)>

Applies to

Sort(Int64[])

Sorts the specified array into ascending numerical order.

[Android.Runtime.Register("sort", "([J)V", "")]
public static void Sort (long[] a);
[<Android.Runtime.Register("sort", "([J)V", "")>]
static member Sort : int64[] -> unit

Parameters

a
Int64[]

the array to be sorted

Attributes

Remarks

Sorts the specified array into ascending numerical order.

Java documentation for java.util.Arrays.sort(long[]).

Portions of this page are modifications based on work created and shared by the Android Open Source Project and used according to terms described in the Creative Commons 2.5 Attribution License.

Applies to

Sort(Int32[])

Sorts the specified array into ascending numerical order.

[Android.Runtime.Register("sort", "([I)V", "")]
public static void Sort (int[] a);
[<Android.Runtime.Register("sort", "([I)V", "")>]
static member Sort : int[] -> unit

Parameters

a
Int32[]

the array to be sorted

Attributes

Remarks

Sorts the specified array into ascending numerical order.

Java documentation for java.util.Arrays.sort(int[]).

Portions of this page are modifications based on work created and shared by the Android Open Source Project and used according to terms described in the Creative Commons 2.5 Attribution License.

Applies to

Sort(Int16[])

Sorts the specified array into ascending numerical order.

[Android.Runtime.Register("sort", "([S)V", "")]
public static void Sort (short[] a);
[<Android.Runtime.Register("sort", "([S)V", "")>]
static member Sort : int16[] -> unit

Parameters

a
Int16[]

the array to be sorted

Attributes

Remarks

Sorts the specified array into ascending numerical order.

Java documentation for java.util.Arrays.sort(short[]).

Portions of this page are modifications based on work created and shared by the Android Open Source Project and used according to terms described in the Creative Commons 2.5 Attribution License.

Applies to

Sort(Double[])

Sorts the specified array into ascending numerical order.

[Android.Runtime.Register("sort", "([D)V", "")]
public static void Sort (double[] a);
[<Android.Runtime.Register("sort", "([D)V", "")>]
static member Sort : double[] -> unit

Parameters

a
Double[]

the array to be sorted

Attributes

Remarks

Sorts the specified array into ascending numerical order.

The < relation does not provide a total order on all double values: -0.0d == 0.0d is true and a Double.NaN value compares neither less than, greater than, nor equal to any value, even itself. This method uses the total order imposed by the method Double#compareTo: -0.0d is treated as less than value 0.0d and Double.NaN is considered greater than any other value and all Double.NaN values are considered equal.

Java documentation for java.util.Arrays.sort(double[]).

Portions of this page are modifications based on work created and shared by the Android Open Source Project and used according to terms described in the Creative Commons 2.5 Attribution License.

See also

  • <xref:Java.Util.Arrays.Sort(System.Double%5b%5d%2c+System.Int32%2c+System.Int32)>

Applies to

Sort(Char[])

Sorts the specified array into ascending numerical order.

[Android.Runtime.Register("sort", "([C)V", "")]
public static void Sort (char[] a);
[<Android.Runtime.Register("sort", "([C)V", "")>]
static member Sort : char[] -> unit

Parameters

a
Char[]

the array to be sorted

Attributes

Remarks

Sorts the specified array into ascending numerical order.

Java documentation for java.util.Arrays.sort(char[]).

Portions of this page are modifications based on work created and shared by the Android Open Source Project and used according to terms described in the Creative Commons 2.5 Attribution License.

Applies to

Sort(Byte[])

Sorts the specified array into ascending numerical order.

[Android.Runtime.Register("sort", "([B)V", "")]
public static void Sort (byte[] a);
[<Android.Runtime.Register("sort", "([B)V", "")>]
static member Sort : byte[] -> unit

Parameters

a
Byte[]

the array to be sorted

Attributes

Remarks

Sorts the specified array into ascending numerical order.

Java documentation for java.util.Arrays.sort(byte[]).

Portions of this page are modifications based on work created and shared by the Android Open Source Project and used according to terms described in the Creative Commons 2.5 Attribution License.

Applies to

Sort(Object[])

Sorts the specified array of objects into ascending order, according to the Comparable natural ordering of its elements.

[Android.Runtime.Register("sort", "([Ljava/lang/Object;)V", "")]
public static void Sort (Java.Lang.Object[] a);
[<Android.Runtime.Register("sort", "([Ljava/lang/Object;)V", "")>]
static member Sort : Java.Lang.Object[] -> unit

Parameters

a
Object[]

the array to be sorted

Attributes

Exceptions

if any element does not implement Comparable, or if compareTo throws for any pair of elements.

Remarks

Sorts the specified array of objects into ascending order, according to the Comparable 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 throw a ClassCastException 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.

Implementation note: This implementation is a stable, adaptive, iterative mergesort that requires far fewer than n lg(n) comparisons when the input array is partially sorted, while offering the performance of a traditional mergesort when the input array is randomly ordered. If the input array is nearly sorted, the implementation requires approximately n comparisons. Temporary storage requirements vary from a small constant for nearly sorted input arrays to n/2 object references for randomly ordered input arrays.

The implementation takes equal advantage of ascending and descending order in its input array, and can take advantage of ascending and descending order in different parts of the same input array. It is well-suited to merging two or more sorted arrays: simply concatenate the arrays and sort the resulting array.

The implementation was adapted from Tim Peters's list sort for Python ( TimSort). It uses techniques from Peter McIlroy's "Optimistic Sorting and Information Theoretic Complexity", in Proceedings of the Fourth Annual ACM-SIAM Symposium on Discrete Algorithms, pp 467-474, January 1993.

Java documentation for java.util.Arrays.sort(java.lang.Object[]).

Portions of this page are modifications based on work created and shared by the Android Open Source Project and used according to terms described in the Creative Commons 2.5 Attribution License.

Applies to

Sort(Object[], IComparator)

Sorts the specified array of objects according to the order induced by the specified comparator.

[Android.Runtime.Register("sort", "([Ljava/lang/Object;Ljava/util/Comparator;)V", "")]
[Java.Interop.JavaTypeParameters(new System.String[] { "T" })]
public static void Sort (Java.Lang.Object[] a, Java.Util.IComparator? c);
[<Android.Runtime.Register("sort", "([Ljava/lang/Object;Ljava/util/Comparator;)V", "")>]
[<Java.Interop.JavaTypeParameters(new System.String[] { "T" })>]
static member Sort : Java.Lang.Object[] * Java.Util.IComparator -> unit

Parameters

a
Object[]

the array to be sorted

c
IComparator

the comparator to determine the order of the array. A null value indicates that the elements' Comparable natural ordering should be used.

Attributes

Remarks

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

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

Implementation note: This implementation is a stable, adaptive, iterative mergesort that requires far fewer than n lg(n) comparisons when the input array is partially sorted, while offering the performance of a traditional mergesort when the input array is randomly ordered. If the input array is nearly sorted, the implementation requires approximately n comparisons. Temporary storage requirements vary from a small constant for nearly sorted input arrays to n/2 object references for randomly ordered input arrays.

The implementation takes equal advantage of ascending and descending order in its input array, and can take advantage of ascending and descending order in different parts of the same input array. It is well-suited to merging two or more sorted arrays: simply concatenate the arrays and sort the resulting array.

The implementation was adapted from Tim Peters's list sort for Python ( TimSort). It uses techniques from Peter McIlroy's "Optimistic Sorting and Information Theoretic Complexity", in Proceedings of the Fourth Annual ACM-SIAM Symposium on Discrete Algorithms, pp 467-474, January 1993.

Java documentation for java.util.Arrays.sort(T[], java.util.Comparator<? super T>).

Portions of this page are modifications based on work created and shared by the Android Open Source Project and used according to terms described in the Creative Commons 2.5 Attribution License.

Applies to