java - containsKey check for hashmap -



java - containsKey check for hashmap -

i have read multiple posts understand this, can't seem quite in on why check if map not contain key before performing set operation? eg,

if(!mymap.containskey(mykey) { mymap.put(mykey,myvalue); }

why need check? either way, map doesn't allow duplicate key, , replaces key new value if key exists. why need check explicitly? check needed implementations of map? sorry if basic question. can't seem find reply exact question. if there posts reply may have missed, please point me them, , sense free mark mine duplicate.

you need check because don't want update map's value if key present. think used block of code map mutable/ modifiable prevents overwriting of values.

java

Comments

Popular posts from this blog

php - Android app custom user registration and login with cookie using facebook sdk -

django - Access session in user model .save() -

php - .htaccess Multiple Rewrite Rules / Prioritizing -