sortWith

fun <T> Array<out T>.sortWith(comparator: Comparator<in T>)
fun <T> Array<out T>.sortWith(comparator: Comparator<in T>)
fun <T> Array<out T>.sortWith(comparator: Comparator<in T>)

Sorts the array in-place according to the order specified by the given comparator.

The sort is stable. It means that equal elements preserve their order relative to each other after sorting.

Common
fun <T> Array<out T>.sortWith(comparator: Comparator<in T>, fromIndex: Int = 0, toIndex: Int = size)

Sorts a range in the array in-place with the given comparator.

The sort is stable. It means that equal elements preserve their order relative to each other after sorting.

Parameters

fromIndex

the start of the range (inclusive) to sort, 0 by default.

toIndex

the end of the range (exclusive) to sort, size of this array by default.

Throws

if fromIndex is less than zero or toIndex is greater than the size of this array.

JS
fun <T> Array<out T>.sortWith(comparator: Comparator<in T>, fromIndex: Int = 0, toIndex: Int = size)

Sorts a range in the array in-place with the given comparator.

The sort is stable. It means that equal elements preserve their order relative to each other after sorting.

Since Kotlin

1.4

Parameters

fromIndex

the start of the range (inclusive) to sort, 0 by default.

toIndex

the end of the range (exclusive) to sort, size of this array by default.

Throws

if fromIndex is less than zero or toIndex is greater than the size of this array.

Native
fun <T> Array<out T>.sortWith(comparator: Comparator<in T>, fromIndex: Int = 0, toIndex: Int = size)

Sorts a range in the array in-place with the given comparator.

The sort is stable. It means that equal elements preserve their order relative to each other after sorting.

Parameters

fromIndex

the start of the range (inclusive) to sort, 0 by default.

toIndex

the end of the range (exclusive) to sort, size of this array by default.

Throws

if fromIndex is less than zero or toIndex is greater than the size of this array.

Common
fun <T> MutableList<T>.sortWith(comparator: Comparator<in T>)
fun <T> MutableList<T>.sortWith(comparator: Comparator<in T>)
fun <T> MutableList<T>.sortWith(comparator: Comparator<in T>)

Sorts elements in the list in-place according to the order specified with comparator.

The sort is stable. It means that equal elements preserve their order relative to each other after sorting.