problem with containsKey for Set

J

Jacek

this is what System.out.println tells me:
C={[<val=M;col=2>, <val=2000;col=1>, <val=40;col=0>]=0},
s=[<val=M;col=2>, <val=2000;col=1>, <val=40;col=0>],
C.containsKey(s)=false

C is a Map, where key is a SortedSet which consists of objects of class
Element implements Comparable.
s is a SortedSet which consists of objects of class Element implements
Comparable.

I thought that C.containsKey(s) would return true in this case...

I looked to API - containsKey "Returns true if this map contains a mapping
for the specified key"

is it possible that C.containsKey(s) returns false, because it contains a
different object of the same class with the same values?
maybe you know where's my problem...
Thanks for any help
 
J

Jacek

I know what was wrong - I didn't have public int hashCode() in my Element
class
sorry for such a stupid question...
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,055
Latest member
SlimSparkKetoACVReview

Latest Threads

Top