• 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
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

compare the collection object

 
Ranch Hand
Posts: 36
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,
I have a collection and I want to compare each object with others

so how can I compare the object.

Please provide me the solution.

Thanks in advance

Manish
 
Rancher
Posts: 3742
16
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
If you just want to check if the object is different to another object, then you need to override the Object.equals() method in your class.
If you want to use the comparison for sorting your objects, then you need your class to implement the Comparable interface.
Have a go at that and if you have any problems, come back and show us your code.
 
manish gupta
Ranch Hand
Posts: 36
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks for your suggestion,

Actually I have a collection of object and I want to do validation
I want to perform two validation
my code like that

if ( dvo1.getMaximumInterval()!=null && !dvo1.getMaximumInterval().equals("") &&dvo1.getMinInterval()!=null && !dvo1.getMinInterval().equals("") &&
dvo2.getMaximumInterval()!=null && !dvo2.getMaximumInterval().equals("") &&
dvo2.getMinInterval()!=null && !dvo2.getMinInterval().equals("")){
if( Integer.parseInt(dvo2.getMinInterval())!=Integer.parseInt (dvo1.getMaximumInterval())+1 ){
logObj.info("gap is there");
returnValue ="failed";
}else{
returnValue ="passed";
return one;
}}
if ( dvo1.getMaximumInterval() ==null ||dvo1.getMaximumInterval().equals("") && dvo1.getMinInterval()==null ||dvo1.getMinInterval().equals("") &&
dvo2.getMaximumInterval()==null ||dvo2.getMaximumInterval().equals("") &&
dvo2.getMinInterval()==null ||dvo2.getMinInterval().equals("")){
logObj.info("two row without min and max");
returnValue ="failed";
return zero;

}

but how check these value while iterating the collection?
Please help me
Thanks
Manish
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic