📜  java 查找列表中的重复元素 - Java 代码示例

📅  最后修改于: 2022-03-11 14:52:12.763000             🧑  作者: Mango

代码示例1
public static Set findDuplicates(List listContainingDuplicates) {
 
        final Set setToReturn = new HashSet();
        final Set set1 = new HashSet();
 
        for (String yourInt : listContainingDuplicates) {
            if (!set1.add(yourInt)) {
                setToReturn.add(yourInt);
            }
        }
        return setToReturn;
    }