anand-k jha wrote:Still lots of confusions .......
Could any body clear it out.
- Anand
put() method returns previous value associated by the key you are putting in the HashMap.
so when you call map.put("A", "BBB"); then put() first goes to find any previous value associated with the key "A", it finds "A" key is used first time, so it finds no value exists for "A" key, so it returns no value means null.
so s1=null;
And assigns "BBB" as value of key "A".
so map=[A=BBB]
Again put() goes to find any value associated with "A" key, this time it sees that "A" is already associated with "BBB" value, so it returns "BBB", so s2="BBB".
And now updates the value of key "A" in map.
so map=[A=DDD]