findDuplicates method

Set<T> findDuplicates()

Finds duplicates and then returns a Set with the duplicated elements. If there are no duplicates, an empty Set is returned.

Implementation

Set<T> findDuplicates() {
  final Set<T> duplicates = <T>{};
  final Set<T> auxSet = HashSet<T>();
  for (final T element in this) {
    if (!auxSet.add(element)) duplicates.add(element);
  }
  return duplicates;
}