> For the complete documentation index, see [llms.txt](https://gold.gitbook.io/kotlin/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://gold.gitbook.io/kotlin/collections/ordering-operations/sorted.md).

# sorted

```kotlin
public fun <T : Comparable<T>> Iterable<T>.sorted(): List<T> {
    if (this is Collection) {
        if (size <= 1) return this.toList()
        @Suppress("UNCHECKED_CAST")
        return (toTypedArray<Comparable<T>>() as Array<T>).apply{ sort() }.asList() }
    return toMutableList().apply { sort() }
}
    

val list = listOf(1, 4, 2, 3, 5)
println(list.sorted())  // [1, 2, 3, 4, 5]    
```
