Câu hỏi phỏng vấn Kotlin
Câu hỏi

How to correctly concatenate a String in Kotlin?

Câu trả lời

Here are a few ways to correctly concatenate strings in Kotlin:

String Interpolation

The most common and concise way to concatenate strings in Kotlin is using string interpolation with the $ symbol:

kotlin Copy
val name = "Alice"
val age = 25
println("My name is $name and I am $age years old.")

Output:

Copy
My name is Alice and I am 25 years old.

String Templates

You can also use string templates to insert expressions inside strings:

kotlin Copy
val x = 5
val y = 10
println("x + y = ${x + y}")

Output:

Copy
x + y = 15

Plus Operator

The + operator can be used to concatenate strings:

kotlin Copy
val firstName = "John"
val lastName = "Doe"
va...
junior

junior

Gợi ý câu hỏi phỏng vấn

middle

How are extensions resolved in Kotlin and what doest it mean?

middle

What is the difference between open and public in Kotlin?

middle

What is the purpose of Unit-returning in functions? Why is VALUE there? What is this V ALUE ?

Bình luận

Chưa có bình luận nào

Chưa có bình luận nào