Difference between MutableList and List in Kotlin

2019-01-26 09:12发布

问题:

  1. What is the difference between MutableList and List in Kotlin?
  2. and what is the use of each type?

回答1:

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.



标签: kotlin