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

  • Home
  • SEARCH
  • 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 5984953
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T22:27:24+00:00 2026-05-22T22:27:24+00:00

Good afternoon In Java, I have HashSet which contain list of Object User which

  • 0

Good afternoon

In Java, I have HashSet which contain list of Object User which has properties:

  • email
  • group
  • machinename

now my hashset has following values (list of above object)

email            | group   | machinename
----------------------------------------
robert@yahoo.com | hewitt  | AP1
Mathew@gmail.com | test    | AP1
melody@app.com   | test    | AP1
nick@ac.co       | test    | AP1
robert@yahoo.com | project | AP1
nick@ac.co       | project | AP1

Now I have to find those records which has same email and machine but different group name which in above case are:

nick@ac.co (which has "project" and "test" group)
robert@yahoo.com (which has "hewitt" and "test" groups)

How can I find that using java code?

  • 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-22T22:27:25+00:00Added an answer on May 22, 2026 at 10:27 pm

    This will do exactly what you want:

    Set<User> users = new HashSet<User>();
    // ...
    
    Map<String, List<User>> hits = new HashMap<String, List<User>>(); 
    
    for (User user : users) {
        String key = user.getMachineName() + user.getEmail();
        List<User> list = hits.get(key);
        if (list == null) {
            list = new ArrayList<User>();
            hits.put(key, list);
        }
        list.add(user);
    }
    
    // Users are now grouped by their "machine name + email" as a single key
    
    for (Map.Entry<String, List<User>> hit : hits.entrySet()) {
        if (hit.getValue().size() < 2) continue;
        System.out.println("These users share the same email and machine name: " 
            + hit.getValue()); // hit.getValue() is an ArrayList<User>
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Good afternoon, i am currently wrestling with an old .dll which functionality I have
Good Afternoon All, I have a table inside a div. The div has a
Good afternoon, I have a web query in Excel 2002 going against a web
Good morning. I have an XML file which contains lists of warning and errors
Good morning / afternoon, I have a problem with LDAP connector, when I use
Good afternoon. Before I begin my explanation, I have had a look at other
Good afternoon people's I have built a jquery plugin that I use on my
Good Afternoon, I have some very basic questions on GUI Event Handling. Firstly with
Good afternoon, I inherited some C# code from years ago. I have refactored it
Good afternoon, This should be an easy one. I've done the cookie-cutter default ASP.NET

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.