0

I am using an arraylist that contains duplicate copies of object. I can determine the duplicate copies using lastIndexOf method. After determination, I can remove that duplicate item from list. Now, AFAIK, on removal of item from list, the overall structure of the list would get damaged. I mean if I remove item number 5 from list, then at location 5, nothing would be there which would utlimatly lead to traversing problem. I have read the stack overflow similar questions and tried every single one like hashset, for me, they dont work. How can I maintain a unique Arraylist containing string only.

4

2 回答 2

3

如果删除第 5 项,位置 5 将不包含“洞”。如果有,列表中的下一项将成为第 5 项。因此,您可以继续从列表中删除项目以实现唯一性。但是如果你想要一个独特的集合,你可以使用一个集合。

于 2013-03-05T21:35:39.620 回答
0

阅读文档是值得的。

public Object remove(int index)

移除此列表中指定位置的元素。将任何后续元素向左移动(从它们的索引中减去 1)。

正如迈克所说,如果重复是一个问题,为什么不使用Set?

于 2013-03-05T21:40:10.790 回答