How to sort the following string array in kotlin in alphabetic order?
val array = arrayOf("abc","bcd","xyz","ghi","acd")
To sort the same array we can use
array.sort()
This inbuilt method will sort in alphabetic order. We can also sort Int Array and other array types using inbuilt sort() method
To sort an array without changing the original we can use
val array = arrayOf("abc","bcd","xyz","ghi","acd")
val sorted = array.sortedArray()
as mentioned above answer by s1m0nw1
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With