Difference between MutableList and List in Kotlin

前端 未结 3 1335
情歌与酒
情歌与酒 2020-12-10 10:42
  1. What is the difference between MutableList and List in Kotlin?
  2. and what is the use of each type?
3条回答
  •  庸人自扰
    2020-12-10 10:52

    From docs:

    List: A generic ordered collection of elements. Methods in this interface support only read-only access to the list; read/write access is supported through the MutableList interface.

    MutableList: A generic ordered collection of elements that supports adding and removing elements.

    You can modify a MutableList: change, remove, add... its elements. In a List you can only read them.

提交回复
热议问题