• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Liutauras Vilda
  • Paul Clapham
Sheriffs:
  • paul wheaton
  • Tim Cooke
  • Henry Wong
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Piet Souris
Bartenders:
  • Mike London

containsAll Method of Set returning false always??

 
Ranch Hand
Posts: 153
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Friends,

I have written the following code.

I am populating both the sets by same method which returns same data from database.

Myobject has 2 getters and setters for name and id.

suppliedSet=getSetData();
myGroupSet=getSetData();


I printed both the values of set overloaded the toString method and equals method to compare Myobject on base of Ids . I found both sets have similar objects(same name and Id) still it returns false.

I have put print statements in equal method also and realised that equals method never gets called. Please help me
if (suppliedSet.containsAll(myGroupSet))
{
doSomeProcess();
}
I am going crazy thinking about this. Its fairly simple. Please help me
 
Sheriff
Posts: 11343
Mac Safari Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Nilesh Raje:
...I have put print statements in equal method also and realised that equals method never gets called...


The check for equality depends on the Set. For example, if it's a HashSet, it's going to call hashCode() first, and only call equals() if elements return the same hashCode. If it's a TreeSet constructed with a Comparator, it's going to use that. If it's a TreeSet without a Comparator, it's going to call compareTo().

What type of Set is it?
[ September 13, 2007: Message edited by: marc weber ]
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic