栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 面试经验 > 面试问答

在自定义ArrayList中仅添加一次项目

面试问答 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

在自定义ArrayList中仅添加一次项目

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



转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/455407.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号