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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T05:01:17+00:00 2026-06-17T05:01:17+00:00

I have 4 classes. One holds information about a customer. The other one about

  • 0

I have 4 classes.
One holds information about a customer. The other one about orders.
2 more classes play the registry role, one is customer registry, the other is orders registry.

Orders registry has a hashmap which looks like this:

private HashMap<Integer, Order> orderRegistryMap = new HashMap<>();

The same goes for customers registry.

private HashMap<Integer, Customer> customersRegistryMap = new HashMap<>();

Class orders has an int orderid. Class customers has an int customerid.
I added demo data through both registries (lets say 1 customer with customerid 100, and one order with orderid 500.

I wrote simple methods to search for orders by orderid or to get a hashmap of all orders.
I also wrote simple methods to search for customers by customerid or to get a hashmap of all customers.

I need help with writing a method which can find a customer by orderid and get all orders which are associated with that customerid.

Any ideas?

  • 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-17T05:01:18+00:00Added an answer on June 17, 2026 at 5:01 am

    The typical way to handle such relations(and this seems like a one to many realtion) is to store a customer id in the order itself. This is done because each order has one and only one customer. if you don’t do that you have no choice but iterate through the array.

    EDIT: for the reverse relation Customer->Orders I would use a reverse registry something like:

    HashMap<Integer/*customer_id*/, 
            List<Integer> /*list of orders for the customer*/> customer_orders;
    

    And keep that in sync with the orders and customers. This will perform as fast as you can get and I don’t think you can use less memory to achieve what you want.

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

Sidebar

Related Questions

I have two classes, basically one holds Members and the other Sessions. They are
I have two classes one of which inherits from the other. Im trying to
I have two classes, one that inherits from the other. The base class is
Need help... I have 3 classes, Manager which holds 2 pointers. One to class
In a project I'm creating, I have various classes. One of my classes has
i have two data classes which hold only data members(no functions). One is CallTask
I have 2 classes where I have one to send commands to a socket,
I have two classes (MVC view model) which inherits from one abstract base class.
I have some classes that, for one reason or another, cannot be or need
Starting to learn Canvas and have two classes so far (main one to call

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.