I have a list of objects (e.g. List and I have to find duplicate in the list. I don't have the source code of UnknownSrcClass and UnknownSrcClass doesn't have hash code and equals implemented. So I can't put it in a Set to find the duplicates
I have below two solution
- Build a
HashMap<String,List<UnknownSrcClass>>where key will be build using the fields responsible for equality check.
Iterate the HashMap if for a key list size > 1 then iterate the list of items and find duplicates
- Put items in a TressSet with Comprator and check for add method's return value.
Please suggest me which one would more efficient performance wise. Per me #3 is better approach.