正如您在评论中提到的,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。



