I need to have clarified what's behind map.put()
method's logic while updating.
By instance:
I have a Map which inside these few records:
{
[K="key1", V="value1"],
[K="key2", V="value2"],
[K="key3", V="value3"]
}
If I wish to update record number two I'd write map.put("key2", "value22")
and Java automatically replace value2
with value22
.
How could do that Java?
If the key had been a complex object composed by a few attributes...
{
[K=new CustomKey("something1.1", "something2.1"), V="value1"],
[K=new CustomKey("something1.2", "something2.2"), V="value2"],
[K=new CustomKey("something1.3", "something2.3"), V="value3"]
}
...and I wish to update value2
searching for it by a key with only one attribute valorized, how is possible to do something like this:
map.put(new CustomKey("something1.2"), "value22");
or do I need to provide exactly the entire CustomKey
object?