Related Post: Kotlin List & Mutable List tutorial with examples > Refer to: I. This example shows how even complex operations can be performed easily with Kotlinâs powerful APIs. This Kotlin tutorial shows you example that uses Partition method to split List, Map of Objects. If multiple pairs have the same key, the resulting map will contain the value from the last of those pairs. Weâre making use of the with scope function here to keep our code tidy. (source) Returns a new MutableMap with the specified contents, given as a list of pairs where the first component is the key and the second is the value. Sales.forEach ĪssertEquals(17, inventory) // 24 - 7 + 0ĪssertEquals(13, inventory) // 14 - 4 + 3ĪssertEquals(11, inventory) // 9 - 5 + 7ĪssertEquals(5, inventory) // 0 - 0 + 5 Let's also suppose that we have a row in our table whose data match the example data we mentioned earlier: 'John', 21, NULL using a JdbcTemplate instance we can do the following: val map: Map jdbcTemplate.Val shipments = mapOf("Chocolate" to 3, "Strawberry" to 7, "Rocky Road" to 5) 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) Creating immutable lists, sets, and maps var numList listOf(3, 1, 4, 1, 5. After a day of receiving shipments and selling ice cream, we need to update our storeâs inventory map. mapOf Example 5-8 shows how to create lists and sets. 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. The plus-method on Map creates a new map that contains the new entry.
0 Comments
Leave a Reply. |