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}")
Output:
x + y = 15
The + operator can be used to concatenate strings:
val firstName = "John"
val lastName = "Doe"
va...
junior
Gợi ý câu hỏi phỏng vấn
Chưa có bình luận nào