I have a bunch of users that I've put into a list, then I have another set of a bunch of users I've added to a separate list. I am trying to compare the first list of objects to the second list and create a new list of the unique objects.
// List creation (new, old, unique)
List<User> listNew = new ArrayList<User>();
List<User> listOld = new ArrayList<User>();
List<User> listUnique = new ArrayList<User>();
...
for (User unique : listNew) {
if (!listOld.contains(unique)) {
listUnique.add(unique);
}
}
So I have this code to do that, but it just duplicates the listNew. How could I compare objects to one another? My class file is
public class User {
private String fName;
private String mInitial;
private String lName;
private String age;
private String city;
private String state;
....