This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
The moose likes Java in General and the fly likes compare the collection object Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "compare the collection object" Watch "compare the collection object" New topic

compare the collection object

manish gupta
Ranch Hand

Joined: Nov 06, 2005
Posts: 36
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

Joanne Neal

Joined: Aug 05, 2005
Posts: 3429
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

Joined: Nov 06, 2005
Posts: 36
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 ){"gap is there");
returnValue ="failed";
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("")){"two row without min and max");
returnValue ="failed";
return zero;


but how check these value while iterating the collection?
Please help me
subject: compare the collection object
Similar Threads
Comparing two Collections for "equality"
How To Compare to Iterators...............?
comparable and compartor
need help
Override Equals with Collections