How to turn a Mutable Collection into an Immutable one

后端 未结 6 1037
醉话见心
醉话见心 2020-12-14 14:52

I was writing a small piece of code in which I internally handle my data in a mutable map, which in turn has mutable lists.

I wanted to expose my data to the API use

6条回答
  •  不知归路
    2020-12-14 15:31

    Simply call toMap() on your MutableMap.

    val myMap = mutableMapOf("x" to "y").toMap()
    

    Done.

    The same also works for lists.

提交回复
热议问题