To concatenate two strings in Kotlin, you can use the `+` operator or the `plus()` method of the String class.
In this example,
str1
and str2
with values "Hello"
and "World"
respectively.str1
and str2
using the +
operator and store the result in result
variable.result
to the console.fun main() {
val str1 = "Hello"
val str2 = "World"
val result = str1 + str2
println(result)
}
HelloWorld
In this example,
str1
and str2
with values "apple"
and "banana"
respectively.str1
and str2
using the plus()
method and store the result in result
variable.result
to the console.fun main() {
val str1 = "apple"
val str2 = "banana"
val result = str1.plus(str2)
println(result)
}
applebanana
In this tutorial, we learned How to Concatenate Two Strings in Kotlin language with well detailed examples.