9/11/2023 0 Comments Kotlin list to set![]() ![]() creation functions for collections Collection Kotlin doesn’t have a dedicated syntax for creating lists or sets, but it does provide us with library functions to facilitate creation. The mutable interfaces map directly to the Java interfaces while the immutable interfaces lack all of the mutator methods of their mutable counterparts. As you may have noticed in the diagram, each Java collection has two representations in Kotlin a read-only one and a mutable one. They are the parents of all the collection classes we will work with. At the top of the hierarchy are the interfaces Iterable and MutableIterable - refer to the big image at the beginning of this article. And some of them lets us work with the collections in pairs, like in a dictionary entry, you’ll have a key with a corresponding value. Some of the collections constrains the uniqueness of the data elements, they won’t allow you to put duplicates. Some of them puts constraints on how we go through the collection, they impose certain order of traversal. The reason it’s called a framework is because the data structures are very diverse, in and of themselves. Although Kotlin didn’t define its own collections code, it did add quite a few convenience functions to the framework, which is a welcome addition because it makes the collections easier to work with.īefore we go to the code examples and more details, something needs to be said why it is called a collections framework. So, if you didn’t skimp on your study of collections while you were in Java, that will certainly come in handy now. There’s no conversion of wrapping involved. The Kotlin collections are actually direct instances of the collections in the JDK. ![]()
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |