Sorts the array in-place.
Since Kotlin
1.3Samples
import kotlin.test.*
fun main() {
val intArray = intArrayOf(4, 3, 2, 1)
println(intArray.joinToString())
intArray.sort()
println(intArray.joinToString())
}
Target: JVMRunning on v.2.1.20
Sorts a range in the array in-place.
Since Kotlin
1.4Parameters
the start of the range (inclusive) to sort, 0 by default.
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.
Samples
import kotlin.test.*
fun main() {
val intArray = intArrayOf(4, 3, 2, 1)
println(intArray.joinToString())
intArray.sort(0, 3)
println(intArray.joinToString())
}
Target: JVMRunning on v.2.1.20
Sorts the array in-place.
Since Kotlin
1.0Samples
import kotlin.test.*
fun main() {
val intArray = intArrayOf(4, 3, 2, 1)
println(intArray.joinToString())
intArray.sort()
println(intArray.joinToString())
}
Target: JVMRunning on v.2.1.20
Sorts the array in-place according to the natural order of its elements.
The sort is stable. It means that equal elements preserve their order relative to each other after sorting.
Since Kotlin
1.0Samples
import kotlin.test.*
fun main() {
class Person(val firstName: String, val lastName: String) : Comparable<Person> {
override fun compareTo(other: Person): Int = this.lastName.compareTo(other.lastName)
override fun toString(): String = "$firstName $lastName"
}
val people = arrayOf(
Person("Ragnar", "Lodbrok"),
Person("Bjorn", "Ironside"),
Person("Sweyn", "Forkbeard")
)
println(people.joinToString())
people.sort()
println(people.joinToString())
}
Target: JVMRunning on v.2.1.20
Sorts a range in the array in-place.
The sort is stable. It means that equal elements preserve their order relative to each other after sorting.
Since Kotlin
1.4Parameters
the start of the range (inclusive) to sort, 0 by default.
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.
Samples
import kotlin.test.*
fun main() {
class Person(val firstName: String, val lastName: String) : Comparable<Person> {
override fun compareTo(other: Person): Int = this.lastName.compareTo(other.lastName)
override fun toString(): String = "$firstName $lastName"
}
val people = arrayOf(
Person("Ragnar", "Lodbrok"),
Person("Bjorn", "Ironside"),
Person("Sweyn", "Forkbeard")
)
println(people.joinToString())
people.sort(0, 2)
println(people.joinToString())
}
Target: JVMRunning on v.2.1.20
Since Kotlin
1.0Sorts the array in-place.
Since Kotlin
1.1Samples
import kotlin.test.*
fun main() {
val intArray = intArrayOf(4, 3, 2, 1)
println(intArray.joinToString())
intArray.sort()
println(intArray.joinToString())
}
Target: JVMRunning on v.2.1.20
Sorts the array in-place according to the natural order of its elements.
The sort is stable. It means that equal elements preserve their order relative to each other after sorting.
Since Kotlin
1.1Samples
import kotlin.test.*
fun main() {
class Person(val firstName: String, val lastName: String) : Comparable<Person> {
override fun compareTo(other: Person): Int = this.lastName.compareTo(other.lastName)
override fun toString(): String = "$firstName $lastName"
}
val people = arrayOf(
Person("Ragnar", "Lodbrok"),
Person("Bjorn", "Ironside"),
Person("Sweyn", "Forkbeard")
)
println(people.joinToString())
people.sort()
println(people.joinToString())
}
Target: JVMRunning on v.2.1.20
Sorts a range in the array in-place.
The sort is stable. It means that equal elements preserve their order relative to each other after sorting.
Since Kotlin
1.4Parameters
the start of the range (inclusive) to sort, 0 by default.
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.
Samples
import kotlin.test.*
fun main() {
class Person(val firstName: String, val lastName: String) : Comparable<Person> {
override fun compareTo(other: Person): Int = this.lastName.compareTo(other.lastName)
override fun toString(): String = "$firstName $lastName"
}
val people = arrayOf(
Person("Ragnar", "Lodbrok"),
Person("Bjorn", "Ironside"),
Person("Sweyn", "Forkbeard")
)
println(people.joinToString())
people.sort(0, 2)
println(people.joinToString())
}
Target: JVMRunning on v.2.1.20
Sorts a range in the array in-place.
Since Kotlin
1.4Parameters
the start of the range (inclusive) to sort, 0 by default.
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.
Samples
import kotlin.test.*
fun main() {
val intArray = intArrayOf(4, 3, 2, 1)
println(intArray.joinToString())
intArray.sort(0, 3)
println(intArray.joinToString())
}
Target: JVMRunning on v.2.1.20
Sorts elements in the list in-place according to their natural sort order.
The sort is stable. It means that equal elements preserve their order relative to each other after sorting.
Since Kotlin
1.1Samples
import kotlin.test.*
fun main() {
val mutableList = mutableListOf(4, 3, 2, 1)
println(mutableList.joinToString())
mutableList.sort()
println(mutableList.joinToString())
}
Target: JVMRunning on v.2.1.20
Deprecated
Use sortWith instead
Replace with
this.sortWith(Comparator(comparison))
Sorts the array in-place according to the order specified by the given comparison function.
The sort is stable. It means that equal elements preserve their order relative to each other after sorting.
Since Kotlin
1.1
Deprecated
Use other sorting functions from the Standard Library
Sorts the array in-place according to the order specified by the given comparison function.
Since Kotlin
1.1Sorts the array in-place according to the natural order of its elements.
The sort is stable. It means that equal elements preserve their order relative to each other after sorting.
Since Kotlin
1.0Throws
Sorts a range in the array in-place.
The sort is stable. It means that equal elements preserve their order relative to each other after sorting.
Since Kotlin
1.0Parameters
the start of the range (inclusive) to sort, 0 by default.
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.
Samples
import kotlin.test.*
fun main() {
class Person(val firstName: String, val lastName: String) : Comparable<Person> {
override fun compareTo(other: Person): Int = this.lastName.compareTo(other.lastName)
override fun toString(): String = "$firstName $lastName"
}
val people = arrayOf(
Person("Ragnar", "Lodbrok"),
Person("Bjorn", "Ironside"),
Person("Sweyn", "Forkbeard")
)
println(people.joinToString())
people.sort(0, 2)
println(people.joinToString())
}
Target: JVMRunning on v.2.1.20
Sorts the array in-place.
Since Kotlin
1.0Samples
import kotlin.test.*
fun main() {
val intArray = intArrayOf(4, 3, 2, 1)
println(intArray.joinToString())
intArray.sort()
println(intArray.joinToString())
}
Target: JVMRunning on v.2.1.20
Sorts the array in-place according to the natural order of its elements.
The sort is stable. It means that equal elements preserve their order relative to each other after sorting.
Since Kotlin
1.0Samples
import kotlin.test.*
fun main() {
class Person(val firstName: String, val lastName: String) : Comparable<Person> {
override fun compareTo(other: Person): Int = this.lastName.compareTo(other.lastName)
override fun toString(): String = "$firstName $lastName"
}
val people = arrayOf(
Person("Ragnar", "Lodbrok"),
Person("Bjorn", "Ironside"),
Person("Sweyn", "Forkbeard")
)
println(people.joinToString())
people.sort()
println(people.joinToString())
}
Target: JVMRunning on v.2.1.20
Sorts a range in the array in-place.
The sort is stable. It means that equal elements preserve their order relative to each other after sorting.
Since Kotlin
1.4Parameters
the start of the range (inclusive) to sort, 0 by default.
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.
Samples
import kotlin.test.*
fun main() {
class Person(val firstName: String, val lastName: String) : Comparable<Person> {
override fun compareTo(other: Person): Int = this.lastName.compareTo(other.lastName)
override fun toString(): String = "$firstName $lastName"
}
val people = arrayOf(
Person("Ragnar", "Lodbrok"),
Person("Bjorn", "Ironside"),
Person("Sweyn", "Forkbeard")
)
println(people.joinToString())
people.sort(0, 2)
println(people.joinToString())
}
Target: JVMRunning on v.2.1.20
Sorts a range in the array in-place.
Since Kotlin
1.0Parameters
the start of the range (inclusive) to sort, 0 by default.
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.
Samples
import kotlin.test.*
fun main() {
val intArray = intArrayOf(4, 3, 2, 1)
println(intArray.joinToString())
intArray.sort(0, 3)
println(intArray.joinToString())
}
Target: JVMRunning on v.2.1.20
Sorts elements in the list in-place according to their natural sort order.
The sort is stable. It means that equal elements preserve their order relative to each other after sorting.
Since Kotlin
1.0Samples
import kotlin.test.*
fun main() {
val mutableList = mutableListOf(4, 3, 2, 1)
println(mutableList.joinToString())
mutableList.sort()
println(mutableList.joinToString())
}
Target: JVMRunning on v.2.1.20
Deprecated (with error)
Use sortWith(comparator) instead.
Replace with
this.sortWith(comparator)
Since Kotlin
1.0
Deprecated (with error)
Use sortWith(Comparator(comparison)) instead.
Replace with
this.sortWith(Comparator(comparison))
Since Kotlin
1.0Sorts the array in-place.
Since Kotlin
1.3Samples
import kotlin.test.*
fun main() {
val intArray = intArrayOf(4, 3, 2, 1)
println(intArray.joinToString())
intArray.sort()
println(intArray.joinToString())
}
Target: JVMRunning on v.2.1.20
Sorts the array in-place according to the natural order of its elements.
The sort is stable. It means that equal elements preserve their order relative to each other after sorting.
Since Kotlin
1.3Samples
import kotlin.test.*
fun main() {
class Person(val firstName: String, val lastName: String) : Comparable<Person> {
override fun compareTo(other: Person): Int = this.lastName.compareTo(other.lastName)
override fun toString(): String = "$firstName $lastName"
}
val people = arrayOf(
Person("Ragnar", "Lodbrok"),
Person("Bjorn", "Ironside"),
Person("Sweyn", "Forkbeard")
)
println(people.joinToString())
people.sort()
println(people.joinToString())
}
Target: JVMRunning on v.2.1.20
Sorts a range in the array in-place.
The sort is stable. It means that equal elements preserve their order relative to each other after sorting.
Since Kotlin
1.4Parameters
the start of the range (inclusive) to sort, 0 by default.
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.
Samples
import kotlin.test.*
fun main() {
class Person(val firstName: String, val lastName: String) : Comparable<Person> {
override fun compareTo(other: Person): Int = this.lastName.compareTo(other.lastName)
override fun toString(): String = "$firstName $lastName"
}
val people = arrayOf(
Person("Ragnar", "Lodbrok"),
Person("Bjorn", "Ironside"),
Person("Sweyn", "Forkbeard")
)
println(people.joinToString())
people.sort(0, 2)
println(people.joinToString())
}
Target: JVMRunning on v.2.1.20
Sorts a range in the array in-place.
Since Kotlin
1.4Parameters
the start of the range (inclusive) to sort, 0 by default.
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.
Samples
import kotlin.test.*
fun main() {
val intArray = intArrayOf(4, 3, 2, 1)
println(intArray.joinToString())
intArray.sort(0, 3)
println(intArray.joinToString())
}
Target: JVMRunning on v.2.1.20
Sorts elements in the list in-place according to their natural sort order.
The sort is stable. It means that equal elements preserve their order relative to each other after sorting.
Since Kotlin
1.3Samples
import kotlin.test.*
fun main() {
val mutableList = mutableListOf(4, 3, 2, 1)
println(mutableList.joinToString())
mutableList.sort()
println(mutableList.joinToString())
}
Target: JVMRunning on v.2.1.20