output is for str array: 1 something output in list: 1 something
changes were reflected in both list and the array why is that?... also in the K&B book the map example that stars at 565
seems that if you change the name attribute on object d1 outside the map, it changes the object d1 originally stored in the map.. why is that?.. can anyone pls explain this a little bit more deeply? thanks in advance.
Here when you set d1.name = "clover"; & call m.get(new Dog("clover")) it first checks for hash code using length of name (here it is 6) ,it matches with key & then it is compared with equals() which also returns true (clover & clover matchs)
you can see hashcode matches(as both arthur & clover name length is 6) but equals does't match(arthur != clover).
Hope you got your answer.
Joined: May 01, 2008
Thanks for your answer.. but I'm still not sure about it..
why changing the name attribute of d1.name="arthur" and looking at the map with map.get("clover") will be related on the test how will these two objects will test each other if one is outside the map? I guess that's what I'm not sure of it, also another question so only creating a List object with Arrays.asList will bound them together? if you create a Set myset = HashSet(Arrays.asList(str)); those will not be bounded?... thanks.