• Post Reply Bookmark Topic Watch Topic
  • New Topic

comparing two hashmaps  RSS feed

 
Nico Fish
Greenhorn
Posts: 20
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have a simple question but I dont understand why I am getting false for this boolean statement.




the output is as follow:


hash compare false
fish.returnHash(){T=[1, 2, 3, 5], G=[], A=[0], C=[4]}
trialSearch.returnHash(){T=[1, 2, 3, 5], G=[], A=[0], C=[4]}


why is it printing false for the boolean statment when the two hashmaps contain the same values and keys?

 
Stefan Evans
Bartender
Posts: 1837
10
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I presume this method "returnHash" is a custom one that returns an object?
Remember that for comparing anything other than primitive types, you should use the .equals method.

And of course it will depend on the implementation of the equals method in this object :-)
 
Campbell Ritchie
Marshal
Posts: 56599
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Well, if you will use the == operator on reference types, what do you expect?
 
Consider Paul's rocket mass heater.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!