I\'ve made my own custom ArrayList like this:
public class Points {
String hoodName;
Double points;
Integer hoodId;
public Points(String hN, Doub
As you mentioned in the comments that Order doesn't matter , I would have an HashSet
to store and check the hood_name
and If you want to get object
by entering hood_name
you can use HashMap
O(1)
time.
So You need to create a HashSet
which will keep track of hood_name
of all objects present in the ArrayList
.
HashSet all_ids=new HashSet();
if (!all_ids.contains(jsonObject.getString("hood_name")))
{
points.add(new Points(jsonObject.getString("hood_name"), jsonObject.getDouble("points"), jsonObject.getInt("hood_id")));
all_ids.add(jsonObject.getString("hood_name")); //You need to add it to set as Now it exists in the list.
}
Further more , If you want to only use ArrayList
to execute this task , You can override equals(Object E)
and hashCode()
methods in Point
class. For more information , refer this.