Created
December 28, 2020 03:48
-
-
Save meidikawardana/89a3e5ce23683adffbed671a2d5a556e to your computer and use it in GitHub Desktop.
Kotlin collections: list, set & map. learned from https://developer.android.com/codelabs/basic-android-kotlin-training-collections
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
fun main() { | |
val numbers = listOf(0, 3, 8, 4, 0, 5, 5, 8, 9, 2) | |
println("list: ${numbers}") | |
println("sorted: ${numbers.sorted()}") | |
val setOfNumbers = numbers.toSet() | |
println("set: ${setOfNumbers}") | |
val set1 = setOf(1,2,3) | |
val set2 = mutableSetOf(3,2,1) | |
println("$set1 == $set2: ${set1 == set2}") | |
println("contains 7: ${setOfNumbers.contains(7)}") | |
val peopleAges = mutableMapOf<String, Int>( | |
"Fred" to 30, | |
"Ann" to 23 | |
) | |
peopleAges.put("Barbara", 42) | |
peopleAges["Joe"] = 51 | |
// add key value with key the same as with one of existing keys | |
// will update the existing key's value | |
peopleAges["Fred"] = 31 | |
println(peopleAges) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment