I got an ArrayList of users who can login to web site multiple times per day. How can I create an ArrayList of unique users out of the first arraylist. In other words I need to ignore multiple logins. If for example there were 20 logins to the web site and all those logins were made by two users then the second list should contain just two user objects. I am newbie to Java programming language and I need help.
Here is the User class:
public class User {
private String id
private String date;
public String getId() {
return id
}
public void setId(String id) {
this.id = id
}
public String getDate() {
return date;
}
public void setDate(String date) {
this.date = date;
}
}
And here is how I was going to solve the issue but for some reason it doesn't work.
ArrayList<User> userList = new ArrayList<>();
ArrayList<User> uniqueUserlist = new ArrayList<>();
String id = null;
for(User user : userList) {
if (user.getId() != id) {
uniqueUserlist.add(user);
}
id = user.getId();
}
Thank you.