Created
August 3, 2020 19:48
-
-
Save Ayeeta/275a4fd1f5c51bb14807ed882df3aed7 to your computer and use it in GitHub Desktop.
About hash maps / dictionaries
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
/** | |
Immutable hash map/dictionary | |
**/ | |
val contacts = mapOf("Tom" to "0780","Peter" to "4784","Derrick" to "6780" ) | |
println(contacts) | |
println(contacts["Tom"]) | |
println(contacts.get("Peter")) | |
println(contacts.values) | |
/** | |
Mutable hash map/dictionary | |
**/ | |
val contactsMap = hashMapOf("Gad" to "8745") | |
contactsMap["Ronny"] = "3245" | |
contactsMap.put("Bonny", "4545") | |
println(contactsMap) | |
contactsMap.remove("Gad") | |
println(contactsMap) | |
//For-loop | |
for((k,v) in contactsMap){ | |
println("$k, $v") | |
} | |
val nums = arrayListOf(3,2,1,4,6) | |
for(num in nums){ | |
println(num) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment