Skip to content

Instantly share code, notes, and snippets.

@Ayeeta
Created August 3, 2020 19:48
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Ayeeta/275a4fd1f5c51bb14807ed882df3aed7 to your computer and use it in GitHub Desktop.
Save Ayeeta/275a4fd1f5c51bb14807ed882df3aed7 to your computer and use it in GitHub Desktop.
About hash maps / dictionaries
/**
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