| Author |
hashset
|
gunjan khanuja
Ranch Hand
Joined: Apr 16, 2012
Posts: 37
|
|
i run this code snippet and this gives me output 3
I understand that hashset contains unique elements so the string s1 and s2 is not added twice but why is Propagate object being added twice..???explain
|
 |
Anayonkar Shivalkar
Bartender
Joined: Dec 08, 2010
Posts: 1295
|
|
Hi gunjan khanuja,
Welcome to CodeRanch!
gunjan khanuja wrote:why is Propagate object being added twice..???explain
Well, I would have liked a 'please' here
Anyways, here's a hint : take a close look at your equals method. What exactly are you trying to equate?
|
Regards,
Anayonkar Shivalkar (SCJP, SCWCD, OCMJD)
|
 |
gunjan khanuja
Ranch Hand
Joined: Apr 16, 2012
Posts: 37
|
|
Well,I am trying to compare the string value with object 's value.But i dont understand the output.
please explain in detail what all is happening in the snippet???
|
 |
Matthew Brown
Bartender
Joined: Apr 06, 2010
Posts: 3791
|
|
Anayonkar's pointed you in the right direction. In your equals() method, you are comparing a String with a Propagate.
|
 |
Seetharaman Venkatasamy
Ranch Hand
Joined: Jan 28, 2008
Posts: 5575
|
|
still not clear? then you customize your equals method as in
|
 |
Helen Ma
Ranch Hand
Joined: Nov 01, 2011
Posts: 451
|
|
|
Another hint : try to System.out.println(h1.str.equals(h2)). Is the answer true or false? I think it is false.
|
 |
 |
|
|
subject: hashset
|
|
|