Excellent work! In this lesson, we’ve learned the following concepts:
- A list is a type of Kotlin Collection that contains ordered elements.
- An immutable list is declared with
listOfand indicates a list whose values cannot change throughout a program.
- A mutable list is declared with
mutableListOfand indicates a list whose values can be altered.
- Elements within a list can be accessed using their index.
sizeproperty returns the number of elements in a collection.
- Immutable lists possess read-only functionalities, meanwhile, mutable lists support both read and write functionalities.
contains()function checks if an element exists in a given list. It returns a Boolean
add()function appends an element to the end of a mutable list.
remove()function removes an element from a mutable list.
random()function generates a random element from a given list.
You’ve covered a major, fundamental programming concept used in most programs to store and manipulate data. Feel free to utilize the empty Review.kt file and output terminal on the right to hone your understanding of lists and practice writing Kotlin code.
Click Up Next when you’re ready to move on.