aspose file tools*
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes hashset Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "hashset" Watch "hashset" New topic
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: 1509
    
    5

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, OCEEJBD)
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: 4422
    
    8

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.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: hashset