

Unlike other languages there is no support for "slicing notation". The sublist(start,end) method gives you the ability to extract a sub-list. To shrink the collection you can use remove and clear which remove one instance of an element and all of the elements respectively. You can also use the addAll method to add a list of elements in one go. The add method adds to the end of the collection by default, but you can insert an element at a specific position.įor example: var a:MutableList = mutableListOf("x","y","z") To add an element beyond what are already there you have to use the add method: var a:MutableList = mutableListOf("x","y","z") If you are familiar with more permissive languages such as JavaScript you might think that this allows you to reference elements that don't exist. The big difference is that you can make the MutableList bigger. You can create a MutableList in the same way as a List: var a:MutableList = mutableListOf("x","y","z")
