Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6791587
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T17:51:52+00:00 2026-05-26T17:51:52+00:00

What is the best way to find and mark duplicate objects in a Collection?

  • 0

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.

  1. Identify all duplicates
  2. Mark each duplicate person indicating it is a duplicate
  3. For each duplicate person, identify the object it is the duplicate of

Is there a simple way of doing this with guava?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T17:51:53+00:00Added an answer on May 26, 2026 at 5:51 pm

    You don’t need Guava to do this:

    List<Person> people = ...
    Map<Name, Person> peopleByName = new HashMap<>();
    for (Person person : people) {
      // Name is a simple value class with equality based on its fields
      Name name = new Name(person.getFirstName(), person.getLastName());
      Person firstPersonWithName = peopleByName.get(name);
      if (firstPersonWithName == null) {
        peopleByName.put(name, person);
      } else {
        // or whatever you do to mark a duplicate
        person.setDuplicateOf(firstPersonWithName);
      }
    }
    

    That said, you could use a Guava Table instead of a Map and avoid needing to create the Name… use first name as the row keys and last name as column keys, say.

    Another choice would be to use Multimaps.index to 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.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Possible Duplicate: What’s the best way to find the inverse of datetime.isocalendar()? I have
What is the best way to find something in a list? I know LINQ
I've got a List of objects - let's say they're Orders. Order OrderID Date
What's the best way to find additional orthonormal columns of Q? I have computed
I have a 1 to 1 map. What's the best way to find keys
Suppose I have a (Spark) label. What is the best way to find the
What is the best way to find if an object is in an array?
What is the best way to find out if a primary key with a
What is the best way to find out whether two number ranges intersect? My
What is the best way to find the total number of words in a

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.