java - 去除List中重复项的方法

标签 java list

Possible Duplicate:
Remove duplicates from a list

Java List 中有没有可以用来删除重复项的方法?

最佳答案

不,java.lang.List 上没有删除重复项的方法。看来设计者预计 List 不会用于担心重复的场景:

Unlike sets, lists typically allow duplicate elements. More formally, lists typically allow pairs of elements e1 and e2 such that e1.equals(e2), and they typically allow multiple null elements if they allow null elements at all. It is not inconceivable that someone might wish to implement a list that prohibits duplicates, by throwing runtime exceptions when the user attempts to insert them, but we expect this usage to be rare.

(taken from java.lang.List Javadoc)

您需要使用Set或实现您自己的方法来删除重复项。

关于java - 去除List中重复项的方法,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5101121/

相关文章:

java - 由于某种原因列表大小回到零

JAVA性能洞察,重构现有代码

java - 无法使用 Android Studio 在 Java 中打印匹配的 HashMap 键

java - 不眨眼地更新 Flex 中的照片

python - 如何拆分具有多个文本列表值的 python 字典,以获得具有相同值的单独键字典?

c++ - 使用 nlohmann json 将整数列表解包为 std::vector<int>

Javafx- 鼠标单击事件可撤消上一次鼠标单击所做的操作

java - 运行时的 MapActivity ClassDefNotFoundException

python - 过滤字典列表

c - 无法释放所有已用内存