Let's learn about a way to combine two collections, and create a new one from them – it's time to zip!Īssume we have two collections, where the elements at each index are somehow related. So far, we have always looked at a single collection, and what we can do with it. If you are doing an operation on a list, which in turn generates a collection for each one of the input elements, consider if flatMap can help you simplify your code! As desired, we end up with a plain list of elements – the list of characters from the names of the original collection. Next, that collection of collections gets flattened. In the example above, the function that we provide creates a list for each element in our input collection, containing the letters of the original string. file.Enter fullscreen mode Exit fullscreen mode Kotlins’ Collections implements interface List of Java. Public inline fun Iterable.filter(predicate: (T) -> Boolean): List How to explain the fact that ArrayList of Java is equal to List of Kotlin? val list: = () * Returns a list containing only elements matching the given. For instance, if you open _Collections.kt file from stdlib you can find many methods similar to this: /** Kotlin has a feature called Extension Functions which enables Kotlin Standard Library (stdlib) to extend functionality of JDK’s classes. This article focuses on some features of llections package. Kotlin’s Collections are based on Java Collection Framework. Let’s look how to use collections in Kotlin together, it will be exciting! This topic is relevant for versed developers that have serious intentions to come to grips with Kotlin and to be in the forefront of the trends, of course. If you missed this topic by some reason, we strongly recommend to take a look at this survey. Developing android app with Kotlin is gaining popularity among the Java developers.
0 Comments
Leave a Reply. |
Details
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |