![]() These classes have no inheritance relation to the Array class, but they have the same set of methods and properties. ![]() This example shows how even complex operations can be performed easily with Kotlin’s powerful APIs. Kotlin version support From version 1.13.0 MockK supports Kotlin 1.4 and higher Known issues PowerMock needs a workaround to run together with MockK 79. Kotlin also has classes that represent arrays of primitive types without boxing overhead: ByteArray, ShortArray, IntArray, and so on. We’re making use of the with scope function here to keep our code tidy. A Kotlin map can be either mutable ( mutableMapOf) or read-only ( mapOf ). We can declare the keys and values to be any type there are no restrictions. The same value can be associated with multiple keys though. Val shipments = mapOf("Chocolate" to 3, "Strawberry" to 7, "Rocky Road" to 5) Kotlin map is a collection of key/value pairs, where each key is unique, and it can only be associated with one value. ![]() We’ll subtract all the entries in the sales map and then add all the entries from the shipments map to update each flavor’s Quantity: val sales = mapOf("Vanilla" to 7, "Chocolate" to 4, "Strawberry" to 5) After a day of receiving shipments and selling ice cream, we need to update our store’s inventory map. The forEach method performs an action on each entry in a given map. As a final example, we’ll use what we’ve learned already and introduce the forEach method.
0 Comments
Leave a Reply. |