Kotlin .reverse()
Published Dec 6, 2024
Contribute to Docs
In Kotlin, the .reverse() function reverses the order of the elements in-place in a specified array.
Syntax
arr.reverse()
arr: A mutable array whose elements will be reversed in place.
Example
The following example demonstrates the usage of the .reverse() function:
fun main() {// Creating an arrayval arr = intArrayOf(3, 7, 11, 15, 19)// Reversing the order of the elements in the arrayarr.reverse()// Printing the modified arrayprintln(arr.contentToString())}
The above code produces the following output:
[19, 15, 11, 7, 3]
Contribute to Docs
- Learn more about how to get involved.
- Edit this page on GitHub to fix an error or make an improvement.
- Submit feedback to let us know how we can improve Docs.
Learn Kotlin on Codecademy
- Looking for an introduction to the theory behind programming? Master Python while learning data structures, algorithms, and more!
- Includes 6 Courses
- With Professional Certification
- Beginner Friendly.75 hours
- Learn Kotlin, the expressive, open-source programming language developed by JetBrains.
- Beginner Friendly.9 hours