![]() In Kotlin, we do have two different kinds of collections one is read-only which is known as immutable collection and the other type of collection is where we can have a write facility as well which is known as mutable collection. In the following example, we will create an immutable list and we will try to manipulate its values. As per the documentation of Kotlin, a List is an ordered collection with access to elements by indices. In this article, we will see how we can create these two types of lists and manipulate the same using Kotlin library function. In the following program, we take a string in str, get the unique characters in the string into a list, and print them to output. In Kotlin, we do have two different kinds of collections one is read-only which is known as immutable collection and the other type of collection is where we can have a write facility as well which is known as mutable collection. To get unique characters in string in Kotlin, fist convert the string to a list of characters using String.toMutableList() function, and then get the distinct of these characters using List.distinct() function. As per the documentation of Kotlin, a List is an ordered collection with access to elements by indices. ![]() Kotlin does not provide any dedicated literal to create a collection. A list is a collection to hold same type of data in a single variable.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |