Skip to content

Commit

Permalink
Add findDuplicates
Browse files Browse the repository at this point in the history
  • Loading branch information
hemanth0525 committed Sep 2, 2024
1 parent f5c7e46 commit 6ebffeb
Showing 1 changed file with 1 addition and 14 deletions.
15 changes: 1 addition & 14 deletions src/main/java/org/apache/commons/collections4/ListUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@
import java.util.Iterator;
import java.util.List;
import java.util.Objects;
import java.util.Set;

import org.apache.commons.collections4.bag.HashBag;
import org.apache.commons.collections4.functors.DefaultEquator;
Expand Down Expand Up @@ -189,19 +188,7 @@ public static <E> List<E> fixedSizeList(final List<E> list) {
* @since 4.5.0-M3
*/
public static <E> List<E> findDuplicates(final List<E> list) {
Objects.requireNonNull(list, "The input list must not be null.");

Set<E> seen = new HashSet<>();
Set<E> duplicates = new HashSet<>();
List<E> result = new ArrayList<>();

for (E element : list) {
if (!seen.add(element) && duplicates.add(element)) {
result.add(element);
}
}

return result;
return CollectionUtils.duplicateList(list);
}

/**
Expand Down

0 comments on commit 6ebffeb

Please sign in to comment.