Kotlin – Append a Character to a String

Append a Character to a String in Kotlin

To append a given character to the end of a string in Kotlin, you can use + operator.

Pass the given string str, and the character ch, as left and right operands respectively to the + operator.

str + ch

The above expression returns a new string which is the result of appending the character to end of the string.

Examples

Append ‘@’ character at the end of “apple”

Consider that we are given a string value of "apple" in string variable str, and would like to append a character, say '@' to the end of the string.

Kotlin Program

fun main() {
    val str = "apple"
    val char = '@'
    val resultingString = str + char
    println(resultingString)
}

Output

apple@