I need List.contains() to compare objects by methods that are like
.equals() [on hold]
I have some methods similar to .equals to compare two objects by different
conditions.
class User {
public String primaryKey;
public String name;
// Very simplified
public boolean equalsByPk(Object obj) {
User user = (User) obj;
return this.primaryKey.equals(user.primaryKey);
}
// Very simplified
public boolean equalsByAllFields(Object obj) {
User user = (User) obj;
return this.primaryKey.equals(user.primaryKey) &&
this.name.equals(user.name);
}
}
I'd like to use them without explicit iteration as I'd be using
List.contains() with User.equals(). How can I do it?
No comments:
Post a Comment