I've made my own custom ArrayList like this:
public class Points {
String hoodName;
Double points;
Integer hoodId;
public Points(String hN, Double p, Integer hI){
hoodName = hN;
points =p;
hoodId = hI;
}
public Double getPoints() {
return points;
}
public Integer getHoodId() {
return hoodId;
}
public String getHoodName() {
return hoodName;
}
}
When I'm adding data from my JSON api it adds item multiple times. I've tried this code to add the items only once it:
if (!points.contains(jsonObject.getString("hood_name"))) {
points.add(new Points(jsonObject.getString("hood_name"), jsonObject.getDouble("points"), jsonObject.getInt("hood_id")));
}
If also tried this:
if (!points.contains(Points(jsonObject.getString("hood_name"), jsonObject.getDouble("points"), jsonObject.getInt("hood_id")))) {
points.add(new Points(jsonObject.getString("hood_name"), jsonObject.getDouble("points"), jsonObject.getInt("hood_id")));
}
This code is working when I use a ArrayList or ArrayList<Integer>
but not when I'm using ArrayList<Points>
Can anyone explain me how I can avoid duplication in my list?