How to correctly concatenate a String in Kotlin?
How to correctly concatenate a String in Kotlin?
Here are a few ways to correctly concatenate strings in Kotlin:
The most common and concise way to concatenate strings in Kotlin is using string interpolation with the $ symbol:
val name = "Alice"
val age = 25
println("My name is $name and I am $age years old.")
Output:
My name is Alice and I am 25 years old.
You can also use string templates to insert expressions inside strings:
val x = 5
val y = 10
println("x + y = ${x + y}")
Đăng nhập để tham gia thảo luận cùng mọi người.
Chưa có bình luận nào
Hãy là người đầu tiên chia sẻ suy nghĩ của bạn.