How to turn a Mutable Collection into an Immutable one

后端 未结 6 1027
醉话见心
醉话见心 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:44

    Use Collections to converts a Mutable list to Immutable list, Example:

    Mutable list:

    val mutableList = mutableListOf()
    

    Converts to Immutable list:

    val immutableList = Collections.unmodifiableList(mutableList)
    

提交回复
热议问题