capitalize
Deprecated
Use replaceFirstChar instead.
Replace with
import java.util.Locale
Content copied to clipboard
replaceFirstChar { if (it.isLowerCase()) it.titlecase(Locale.getDefault()) else it.toString() }Content copied to clipboard
Returns a copy of this string having its first letter titlecased using the rules of the default locale, or the original string if it's empty or already starts with a title case letter.
The title case of a character is usually the same as its upper case with several exceptions. The particular list of characters with the special title case form depends on the underlying platform.
Since Kotlin
1.0Samples
import java.util.Locale
import kotlin.test.*
fun main() {
//sampleStart
println("abcd".capitalize()) // Abcd
println("Abcd".capitalize()) // Abcd
//sampleEnd
}