Best Way to Convert ArrayList to String in Kotlin

前端 未结 2 1789
天涯浪人
天涯浪人 2021-02-18 13:26

I have an ArrayList of String in kotlin

private val list = ArrayList()

I want to convert it into String with a separ

2条回答
  •  你的背包
    2021-02-18 13:52

    Kotlin as well has method for that, its called joinToString.

    You can simply call it like this:

    list.joinToString());

    Because by default it uses comma as separator but you can also pass your own separator as parameter, this method takes quite a few parameters aside from separator, which allow to do a lot of formatting, like prefix, postfix and more.

    You can read all about it here

提交回复
热议问题