Kotlin List.asReversed()
The Kotlin List.asReversed() function is used to get reversed read-only view of this List.
Syntax
The syntax of List.asReversed() function is
</>
Copy
List.asReversed()
Examples
In the following program, we take a list of integers and reverse the list using asReversed().
Main.kt
</>
Copy
fun main(args: Array<String>) {
var list = listOf(25, 50, 75, 100)
var result = list.reversed()
println(result)
}
Output
[100, 75, 50, 25]
Conclusion
In this Kotlin Tutorial, we learned how to get a reversed view of this list, using Kotlin List.asReversed() function.