Using a stream, how to sort a list of objects by field (in my case ,componentCode
) that has the maximum number of duplicates, and then find distinct
I tried something like this, but how to add the size of the duplicates when sorting.
List<String> conflictingComponentsCode = componentWarnings.stream()
.sorted(Comparator.comparing(ComponentErrorDetail::getComponentCode))
.map(ComponentErrorDetail::getComponentCode)
.distinct()
.collect(Collectors.toList());