If I want to honest you I don't know work by any collection in android or and java, but my question and my purpose, I want remove duplicate item in ArrayList of My Model or my class this is my Model in below:
public class PersonClass {
private String ID;
private String Name;
private String Family;
private String Nickname;
private String Email;
private String Mobile;
private Date BirthDate;
private boolean Admin;
private boolean Gender;
private String ThumbnailURL;
public PersonClass() {
}
public PersonClass(String ID, String name, String family, String nickname, String email, String mobile, Date birthDate, boolean admin, boolean gender, String thumbnailURL) {
this.ID = ID;
Name = name;
Family = family;
Nickname = nickname;
Email = email;
Mobile = mobile;
BirthDate = birthDate;
Admin = admin;
Gender = gender;
ThumbnailURL = thumbnailURL;
}
public String getID() {
return ID;
}
public void setID(String ID) {
this.ID = ID;
}
public String getName() {
return Name;
}
public void setName(String name) {
Name = name;
}
public String getFamily() {
return Family;
}
public void setFamily(String family) {
Family = family;
}
public String getNickname() {
return Nickname;
}
public void setNickname(String nickname) {
Nickname = nickname;
}
public String getEmail() {
return Email;
}
public void setEmail(String email) {
Email = email;
}
public String getMobile() {
return Mobile;
}
public void setMobile(String mobile) {
Mobile = mobile;
}
public Date getBirthDate() {
return BirthDate;
}
public void setBirthDate(Date birthDate) {
BirthDate = birthDate;
}
public boolean isAdmin() {
return Admin;
}
public void setAdmin(boolean admin) {
Admin = admin;
}
public boolean isGender() {
return Gender;
}
public void setGender(boolean gender) {
Gender = gender;
}
public String getThumbnailURL() {
return ThumbnailURL;
}
public void setThumbnailURL(String thumbnailURL) {
ThumbnailURL = thumbnailURL;
}
public static void LogConsole(PersonClass Person) {
Log.i(MyApplication.LOG_TAG, "ID =" + Person.getID());
Log.i(MyApplication.LOG_TAG, "Name :" + Person.getName());
Log.i(MyApplication.LOG_TAG, "Family :" + Person.getFamily());
Log.i(MyApplication.LOG_TAG, "Nickname :" + Person.getNickname());
Log.i(MyApplication.LOG_TAG, "Email :" + Person.getEmail());
Log.i(MyApplication.LOG_TAG, "Mobile :" + Person.getMobile());
Log.i(MyApplication.LOG_TAG, "BirthDate :" + Person.getBirthDate());
Log.i(MyApplication.LOG_TAG, "Admin :" + Person.isAdmin());
Log.i(MyApplication.LOG_TAG, "Gender :" + Person.isGender());
Log.i(MyApplication.LOG_TAG, "ThumbnailURL :" + Person.getThumbnailURL());
}
}
and Should be mentioned I could by hashset and String Class remove duplicate Array list of Array List of Person Class
AcceptList = WebService.MateList(AcceptRecordsJSONArray);
ArrayList<String> IDs1 = new ArrayList<>(AcceptList.size());
for (PersonClass person : AcceptList)
IDs1.add(person.getID());
Log.e(MyApplication.LOG_TAG, "-------------------------------------IDs1(1)---------------------------------------");
for (String ID : IDs1)
Log.i(MyApplication.LOG_TAG, "First time->ID=" + ID);
Log.e(MyApplication.LOG_TAG, "-------------------------------------IDs1(1)---------------------------------------");
Set<String> set = new LinkedHashSet<>(IDs1);
IDs1.clear();
IDs1.addAll(set);
Log.e(MyApplication.LOG_TAG, "-------------------------------------IDs1(2)---------------------------------------");
for (String ID : IDs1)
Log.i(MyApplication.LOG_TAG, "Second time->ID=" + ID);
Log.e(MyApplication.LOG_TAG, "-------------------------------------IDs1(2)---------------------------------------");
Log.e(MyApplication.LOG_TAG, "-------------------------------------AcceptList(1)---------------------------------------");
for (PersonClass person : AcceptList)
PersonClass.LogConsole(person);
Log.e(MyApplication.LOG_TAG, "-------------------------------------AcceptList(1)---------------------------------------");
ArrayList<PersonClass> AcceptList2 = removeDuplicates(AcceptList);
Log.e(MyApplication.LOG_TAG, "-------------------------------------AcceptList(2)---------------------------------------");
for (PersonClass person : AcceptList2)
PersonClass.LogConsole(person);
Log.e(MyApplication.LOG_TAG, "-------------------------------------AcceptList(2)---------------------------------------");