What is the best way to find and mark duplicate objects in a Collection? Let us say we have a List persons and our duplicate strategy is based on exact match of first name and last name.
- Identify all duplicates
- Mark each duplicate person indicating it is a duplicate
- For each duplicate person, identify the object it is the duplicate of
Is there a simple way of doing this with guava?
You don’t need Guava to do this:
That said, you could use a Guava
Tableinstead of aMapand avoid needing to create theName… use first name as the row keys and last name as column keys, say.Another choice would be to use
Multimaps.indexto index all the people in your list by name. Then for every list of people mapped to a particular name, the first person would be the first person with that name from your list and the others would be duplicates.