posted 17 years ago
Hey Serch Hdez,
Answer to your first Question is,
When you use the asList() method, the array and
the List become joined at the hip. When you update one of them, the other gets
updated automatically.
& for your second question is that if you change the name attribute on object d1 outside the map,
it DOES NOT changes the object d1 originally stored in the map..
it can be explained this way...,
d1.name = "clover";
System.out.println(m.get(new Dog("clover"))); // #2
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)
But taking example .,
d1.name = "arthur";
System.out.println(m.get(new Dog("clover")));
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.