Suppose I have two objects of same class for example:
public class Example {
String name;
String rollNo;
String address;
String phoneNo;
String city;
}
Example obj1 = new Example();
obj1.name = "Name";
obj1.rollNo = "10";
obj1.address = "Address";
obj1.phoneNo = "Phone Number";
obj1.city = "City";
Example obj2 = new Example();
obj2.name = "Name";
obj2.rollNo = "10";
obj2.address = "Address";
obj2.phoneNo = "Phone Number";
obj2.city = "City";
Here I want to compare obj1
with obj2
the catch is I don't want to do this with if condition i.e. getting each member variable of obj1
then comparing it with obj2
variable.
equals
method of java.lang.Object
class will not work here as it compares object reference.
My question is, is there any Java API which will compare two objects and its member variables.