I have the simple ArrayLists of the member class:
ArrayList<Member> mGroupMembers = new ArrayList<>();
ArrayList<Member> mFriends = new ArrayList<>();
Member class:
public class Member {
private String userUID;
private String userName;
public String getUserUID() {
return userUID;
}
public String getUserName() {
return userName;
}
public void setUserName(String userName) {
this.userName = userName;
}
public void setUserUID(String userUID) {
this.userUID = userUID;
}
}
The ArrayList for friends contains all the users friends. What I simply wish to do is remove from the friends list, group members if present with:
mFriends.removeAll(mGroupMembers);
Yet it does nothing to the mFriends list...
Looking at the log statements, the friend does in fact appear within the mGroupMember list.
Why doesn't this work?
equalsmethod inMemberclass I suspect that your lists doesn't contain same objects but only similar ones (with similar states).Memberobjects in the lists. As Pshemo said, since you haven't definedequalsforMember, it will useObject'sequals, which won't be true for equivalentMemberobjects. You need to overrideequals(and thus alsohashCode).