[int compare(E a, E b)]
) Sorts this list according to the order specified by the compare
function.
The compare
function must act as a Comparator.
List<String> numbers = ['one', 'two', 'three', 'four'];
// Sort from shortest to longest.
numbers.sort((x, y) => x.length.compareTo(y.length));
numbers.join(', '); // 'one, two, four, three'
The default List implementations use Comparable.compare if
compare
is omitted.
List<int> nums = [13, 2, -11];
nums.sort();
nums.join(', '); // '-11, 2, 13'
Source
/**
* Sorts this list according to the order specified by the [compare] function.
*
* The [compare] function must act as a [Comparator].
* List<String> numbers = ['one', 'two', 'three', 'four'];
* // Sort from shortest to longest.
* numbers.sort((x, y) => x.length.compareTo(y.length));
* numbers.join(', '); // 'one, two, four, three'
*
* The default List implementations use [Comparable.compare] if
* [compare] is omitted.
*
* List<int> nums = [13, 2, -11];
* nums.sort();
nums.join(', '); // '-11, 2, 13'
*/
void sort([int compare(E a, E b)]);