This article explores different ways to convert a primitive char value to its equivalent String in Kotlin.

1. Using toString() function

The standard approach to convert a char to a string in Kotlin is with the toString() function.

Download Code

2. Using String Concatenation

Alternatively, you can concatenate the given char with an empty string to get a string object.

Download Code

 
You can also use the plus() function, which is effectively the same as using the + operator. It can accept character or any other datatype value.

Download Code

3. Using String Constructor

The idea is to wrap the specified character inside a character array and then pass the array to the String constructor. The String constructor converts the characters in the specified array to a string.

Download Code

4. Using String.format() function

Finally, you can use the String.format() function that returns a formatted string from the specified char arguments.

Download Code

5. Using String templates

Finally, you can use String templates to convert a char to a string. It typically consists of a name or an expression, preceded by a dollar sign ($):

Download Code

That’s all about converting a char to a string in Kotlin.