This article explores different ways to concatenate two strings in Kotlin.

1. Using + Operator

The + operator is one of the widely used approaches to concatenate two strings in Kotlin.

Download Code

 
Alternatively, you can use the plus() function to concatenate one string at the end of another string.

Download Code

2. Using StringBuilder

The recommended way to concatenate two strings in Kotlin is StringBuilder. It is append() function is overloaded to accept different data types.

Download Code

 
You can easily extend the solution for concatenating multiple strings:

Download Code

3. Using String Templates

Finally, you can easily concatenate multiple strings using string templates. The String literals may contain template expressions, i.e., pieces of code that are evaluated and whose results are concatenated into the string.

Download Code

4. Using joinToString() function

If you want to concatenate all the list elements with a separator, you can use the joinToString() function.

Download Code

That’s all about concatenating two strings in Kotlin.