M.J. M.J. - 1 year ago 108
Java Question

how to equate two objects in java

Is there a way in which we can equate two objects. I know that we can use equals, but the problem is that I need to write a utility which can compare any two objects implementing same interface. Now the object can have 1 attribute, or 2 attribute or can have 100 attribute. and i need to compare each and every attribute to prove then exactly equal.

Please Help.

Answer Source

You may have a look at the Apache Commons helper classes EqualsBuilder and HashCodeBuilder. These classes provides methods to build good equals and hashCode method for any class.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download