Last active
December 28, 2020 03:49
-
-
Save meidikawardana/087b1904103ab63719041af7b6e46d04 to your computer and use it in GitHub Desktop.
Kotlin forEach, map, filter operations learned from https://developer.android.com/codelabs/basic-android-kotlin-training-collections
This file contains 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 peopleAges = mutableMapOf<String, Int>( | |
"Fred" to 30, | |
"Ann" to 23 | |
) | |
peopleAges.put("Barbara", 42) | |
peopleAges["Joe"] = 51 | |
peopleAges["Fred"] = 31 | |
peopleAges.forEach { print("${it.key} is ${it.value}, ") } | |
println() | |
println(peopleAges.map { "${it.key} is ${it.value}" }.joinToString(", ") ) | |
println() | |
println(peopleAges) | |
val filteredNames = peopleAges.filter { it.key.length < 4 } | |
println(filteredNames) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment