Compartir a través de


IList.Sort(IComparator) Method

Definition

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

c
IComparator

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:

&#064;Override
            public void sort(Comparator&lt;? super E&gt; c) {
              Object[] elements = toArray();
              Arrays.sort(elements, c);
              ListIterator&lt;E&gt; iterator = (ListIterator&lt;Object&gt;) 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.

Applies to