最佳答案
不,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/