正如您在评论中提到的,Order无关紧要,我将有一个HashSet<String>
to存储并检查hood_name
和。如果要object
通过输入来获取,则hood_name
可以使用HashMap<String,Point
,它可以O(1)
及时返回对象。
因此,您需要创建一个HashSet<String>
,以跟踪中存在hood_name
的所有对象ArrayList<Points>
。
HashSet<String> all_ids=new HashSet<String>();
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.
}
此外,如果您只想用来ArrayList<Point>
执行此任务,则可以在类中重写equals(ObjectE)
和hashCode()
方法Point
。