This week's book giveaway is in the Clojure forum.
We're giving away four copies of Clojure in Action and have Amit Rathore and Francis Avila on-line!
See this thread for details.
Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

hashset

 
gunjan khanuja
Ranch Hand
Posts: 37
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator



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
Posts: 1557
5
Eclipse IDE Java Linux
  • 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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?
 
gunjan khanuja
Ranch Hand
Posts: 37
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 4549
8
Java Netbeans IDE Scala
  • 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Anayonkar's pointed you in the right direction. In your equals() method, you are comparing a String with a Propagate.

 
Seetharaman Venkatasamy
Ranch Hand
Posts: 5575
Eclipse IDE Java Windows XP
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
still not clear? then you customize your equals method as in
 
Helen Ma
Ranch Hand
Posts: 451
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic