Hey guys, I recently started coding on Hackerrank ...
# kontributors
n
Hey guys, I recently started coding on Hackerrank using Kotlin and I switched from Java because it saved me from lot of boilerplate code. But there are few instances which is still same as Java and kind of killed my Kotlin experience. - HashMap still doesn’t has update method Hence, i want to work on developing update method for MutableMap<K,V>. Is there anything that I should follow or know before submitting pull request?
s
You mean the
put
method on a Java Map? This is how you can update any mutable map....
g
HashMap is mutably in Kotlin. What do you mean?
s
This should work
Copy code
val myMap = HashMap<String,String>()
myMap.put("key", "value")
g
yes, or
Copy code
val map = hashMapOf("key" to "value")
map["key"] = "newValue"
s
Exactly... maybe Navi means something else with 'update'... not sure.
n
I’m really sorry to bring this up. This seems to be my ignorance of basic java. I meant exactly what Andrey have offered and also MutableMaps has replace method that does exactly the same and return Boolean/old value depending upon the overloaded method used.
Thanks for quick response though 😊