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 7162599
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T13:45:43+00:00 2026-05-28T13:45:43+00:00

I have an entity that needs to be grouped several times by three of

  • 0

I have an entity that needs to be grouped several times by three of their properties, which enable a finer selection from left to right. Let’s say I have this class:

public class Person {
    private String gender;
    private String state;
    private String age;
}

Each property can hold the same value multiple times and I would like to group them accordingly. So that in the end I have the following data structure:

m --> France  --> 20 --> Person1
                         Person2
                  21 --> Person3
                         Person4
      Germany --> 20 --> Person5
                         ...

I hope you get the idea. Currently I use a deeply nested Map construction to achieve this: Map<String, Map<String, Map<String, Person>>>

Then I check for existing keys as in this answer: Group by field name in Java for each level of the Map and finally add my object to the “deepest” map.

This should work although not tested yet, but is there any better way to do this? As in better readable or faster execution

Since it is only one for loop the execution time should be O(n) which is quite alright, but still, this does not seem to be the best solution.

  • 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-28T13:45:44+00:00Added an answer on May 28, 2026 at 1:45 pm

    You can implement a custom Comparator that compares only properties you need and skipping others. Then you can use Collections.sort(list, comparator) method to sort the object

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

Sidebar

Related Questions

I have an entity in my system, which naturally needs an identifier so that
I have an entity that maps to an external oracle table which is one
I have a Logging Entity that needs to map an Entity that is a
I have a C# application that needs to get variable-length data passed back from
I have a JsonStore that needs to return from an HTTP request that takes
I have a single entity that always duplicate a row when it needs to
I have an entity that has a collection in it. The collection is a
I have an entity that contains a list of other entities. The list of
Imagine you have an entity that has some relations with other entities and you
Let's say we have an entity that has attributes att1 and att2, where att1

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.