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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T06:26:10+00:00 2026-06-12T06:26:10+00:00

I am not sure what data structure I should use to solve it, I

  • 0

I am not sure what data structure I should use to solve it,
I have a list of categories and list of values that are associated to them as following:

Categories           Values 
Smart             **person1**,person2
Handsome          person3,person6,**person1**
Hard-Working      person7,person9

For example, person1 is Smart and Handsome because he is in both Handsome and Smart categories. (a value(person) can be in many categories) and person2 is Smart but is not Handsome.

person object has name,age and gender for example person 1 is

John 43 Male

I am wondering how I can design it, I was thinking of a two-dimention array but it is not a good idea as I would have some spare places

Cat1 v3,v6 Spare Spare
Cat2 v10 Spare Spare Spare
cat4 v6,v7,v8,v9

I suppose the best is to have a list but not sure how to find out which value is for which category or categories ( like V6 in above example that is associated to both cat1 and cat4)

 V3 v6 v7 v8 v9 v10
  • 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-06-12T06:26:11+00:00Added an answer on June 12, 2026 at 6:26 am

    You could use something like

    Map<Category, List<Person>>

    Since Map should provide O(1) access, you want your key to be what you use to look up the most (Category in your case, from what I gather). So if you have

    Map<Category, List<Person>> categoryLookup = new HashMap<Category, ArrayList<Person>>();

    you can do

    List<Person> values = myCategoryLookup.get(someCategory);

    and then iterate over the values. References to the same value can be in multiple lists — that is not a problem.

    For Yameo below, if you want to get categories for a person, you can either

    1. have Person maintain a list of its categories
    2. “reverse” the datastructure above; i.e. also maintain a Map<Person, List<Category>>

    The alternative to these solutions is to set the relationships in the Category and Person classes themselves. For example, Person would have a List<Category> as one of its class properties, and similarly Category would have a List<Person> as one of its class properties. But I get the sense this is more a data-structures question. This what you would probably do if you had a database that contains the actual data and were going to use an ORM tool to map the data to Java classes.

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

Sidebar

Related Questions

I'm not even sure that Postgres' HStore data type can contain nested hashes, and
Possible Duplicate: What data-structure should I use to create my own “BigInteger” class? Out
Im not sure how to output MySQL data into formats below. (eg: timelist, usersex,
Not sure what could be the problem. I'm dumping data from an array $theArray
I am fetching data from mysql to a page, i am not sure if
My XML Feed looks like this http://tinyurl.com/6wc6fel Not sure how to read the data
I'm looping my object data but am getting this undefined value. Not sure why
I'm not quite sure why if I try to free the data I get
I'm implementing a search before data entry, to make sure the user is not
I'm looking for the proper data structure for this scenario. I have boost available

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.