Need to find whether a list of objects has duplicates or not?

I had an entity and I need to find whether it has duplicates or not(Same record more no.of times with all fields same). If it has duplicates I need to remove and show only one out of them. How can it be possible,Please provide me a solution that is fast, this operation should not take more time. Thank you.
2 answers

You could try and perform a oql query in java with a select distinct.

Then from the resulting IDataTable get the Id's of the objects in an ArrayList.

The perform a Core.retrieveIdList with the arraylist as input and return the list.

This will provide the microflow with the needed distinct list of objects.


There is even a native Mx solution without having to know OQL or other technologies that I would try myself:

- copy the list (1) to list (2)

- loop through list (1)


- create a list (3) of all objects in list (2) with the same i as the (list (1)) iterator

- subtract list (3) from list (2)

- if list (3) = empty then the iterator is a duplicate

- if list (3) != empty remove the iterator from list (1)


Now list(1) contains only the duplicates!