Solution 2 is not correct, because it's perfectly fine if the property
phone
of both objects is null.
private static boolean myequals(String str1, String str2) {
return str1 == null ? str2 == null : str1.equals(str2);
}
.....
Customer p1 = (Customer) obj;
return myequals(this.name, p1.name) && myequals(this.id, p1.id) && myequals(this.city, p1.city) && myequals(his.phone,p1.phone) && myequals(this.email, p1.email);