Kotlin - How to correctly concatenate a String

前端 未结 8 928
陌清茗
陌清茗 2020-12-14 05:29

A very basic question, what is the right way to concatenate a String in Kotlin?

In Java you would use the concat() method, e.g.

String a         


        
8条回答
  •  太阳男子
    2020-12-14 06:02

    Yes, you can concatenate using a + sign. Kotlin has string templates, so it's better to use them like:

    var fn = "Hello"
    var ln = "World"
    

    "$fn $ln" for concatenation.

    You can even use String.plus() method.

提交回复
热议问题