Convert Character to String in Kotlin

thumbnail

In this tutorial You will learn to convert a character (char) to a string in Kotlin.

Example: Convert character to string in Kotlin

fun main(args: Array<String>) {
    val ch = 'a'
    val st = Character.toString(ch)
    // Alternatively
    // st = String.valueOf(ch);
    println("The string is: $st")
}

The output will be:

The string is: a

From the code above, we have created a character and stored in the variable ch. We use the Character class’s toString() method to convert character to the string st. You can also use String’s valueOf() method conversion. However, both internally are the same.

Read More

Back To Top