Kotlin - How to correctly concatenate a String

前端 未结 8 919
陌清茗
陌清茗 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.

    0 讨论(0)
  • 2020-12-14 06:06

    yourString += "newString"

    This way you can concatenate a string

    0 讨论(0)
提交回复
热议问题