Extension function of String class

  • A+
Category:Languages

I want to create an extension function of String which takes a String and returns a new String with the characters as the first, but sorted in ascending order. How can I do this? I am new to Kotlin.

 


fun String.ascending() = String(toCharArray().sortedArray()) 

Then:

println("14q36w25e".ascending())  // output "123456eqw" 

Comment

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen: