- What is the difference between MutableList and List in Kotlin?
- 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.