hemanth0525 commented on PR #537:
URL:
https://github.com/apache/commons-collections/pull/537#issuecomment-2323160296
> Since the result is effectively a set and the input does not have to be
restricted to a list, it would be better to do this IMO:
>
> ```java
> public static <E> Set<E> duplicates(final Collection<E> list) {
> final HashSet<E> dups = new HashSet<>();
> final HashSet<E> set = new HashSet<>();
> for (E e : list) {
> (set.contains(e) ? dups : set).add(e);
> }
> return dups;
> }
> ```
>
> and put it in `CollectionUtils` probably.
Thanks for the feedback. The `ListUtils` implementation is tailored for
`List<E>`, preserving the order of elements and identifying duplicates where
the sequence matters. This approach is particularly useful in scenarios such as:
* **Preserving Order**: When the sequence of elements is important, such as
in order-sensitive algorithms or data processing tasks.
* **List-Specific APIs**: When working with APIs that return or expect
`List`, ensuring that the utility aligns with the data structure's inherent
properties.
* **Performance Considerations**: In cases where developers need efficient
duplicate detection while maintaining the list's order, which can be crucial in
performance-sensitive applications.
Keeping this method in `ListUtils` supports these specific needs and
maintains consistency for developers working with ordered collections.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]