IList.Sort(IComparator) Method
Definition
Important
Some information relates to prerelease product that may be substantially modified before it’s released. Microsoft makes no warranties, express or implied, with respect to the information provided here.
Sorts this list according to the order induced by the specified
Comparator
.
[Android.Runtime.Register("sort", "(Ljava/util/Comparator;)V", "GetSort_Ljava_util_Comparator_Handler:Java.Util.IList, Mono.Android, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null", ApiSince=24)]
public virtual void Sort (Java.Util.IComparator? c);
[<Android.Runtime.Register("sort", "(Ljava/util/Comparator;)V", "GetSort_Ljava_util_Comparator_Handler:Java.Util.IList, Mono.Android, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null", ApiSince=24)>]
abstract member Sort : Java.Util.IComparator -> unit
override this.Sort : Java.Util.IComparator -> unit
Parameters
the Comparator
used to compare list elements.
A null
value indicates that the elements'
Comparable natural ordering should be used
- Attributes
Remarks
Sorts this list according to the order induced by the specified Comparator
.
All elements in this list must be mutually comparable using the specified comparator (that is, c.compare(e1, e2)
must not throw a ClassCastException
for any elements e1
and e2
in the list).
If the specified comparator is null
then all elements in this list must implement the Comparable
interface and the elements' Comparable natural ordering should be used.
This list must be modifiable, but need not be resizable.
For apps running on and targeting Android versions greater than Nougat (API level > 25
), Collections#sort(List)
delegates to this method. Such apps must not call Collections#sort(List)
from this method. Instead, prefer not overriding this method at all. If you must override it, consider this implementation:
@Override
public void sort(Comparator<? super E> c) {
Object[] elements = toArray();
Arrays.sort(elements, c);
ListIterator<E> iterator = (ListIterator<Object>) listIterator();
for (Object element : elements) {
iterator.next();
iterator.set((E) element);
}
}
Added in 1.8.
Java documentation for java.util.List.sort(java.util.Comparator<? super E>)
.
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.