sortedWith

Returns a list of all elements sorted according to the specified comparator.

fun <T> Array<out T>.sortedWith(comparator: Comparator<in T>): List<T>(source)
val words = arrayOf("banana", "apple", "cherry")
val sorted = words.sortedWith(Comparator { a, b -> a.length - b.length })
println(sorted)   // [apple, banana, cherry]

Source