Note that altering a mutable collection doesn't require it to be a var. Val numbers = mutableListOf("one", "two", "three", "four") Mutable collections provides both read and write methods. When you run the above Kotlin program, it will generate the following output: Val numbers = listOf("one", "two", "three", "four") Immutable Collection or simply calling a Collection interface provides read-only methods which means once a collection is created, we can not change it because there is no method available to change the object created. Elements can occur more than once in a list. Kotlin provides the following types of collection: Kotlin - Collections Kotlin List - List is an ordered collection with access to elements by indices. Keys are unique, and each of them maps to exactly one value. Kotlin Map - Map (or dictionary) is a set of key-value pairs. In many apps, youve probably seen data displayed as a list: contacts. Kotlin Set - Set is a collection of unique elements which means a group of objects without repetitions. Learn how to use arrays and collections, including lists, sets, and maps. Kotlin List - List is an ordered collection with access to elements by indices. The following collection types are relevant for Kotlin: The Kotlin Standard Library provides a comprehensive set of tools for managing collections. A collection usually contains a number of objects of the same type and Objects in a collection are called elements or items. Collections are a common concept for most programming languages.
0 Comments
Leave a Reply. |