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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T00:12:39+00:00 2026-05-14T00:12:39+00:00

I have a large number of objects which are identified by names (strings). So,

  • 0

I have a large number of objects which are identified by names (strings). So, I would like to have a kind of mapping from object name to the class instances.

I was told that in this situation I can use a “repository” class which works like that:

Server myServer = ServerRepository.getServer("NameOfServer");

So, if there is already an object (server) with the “NameOfServer” it will be returned by the “getServer”. If such an object does not exist yet, it will be created and returned by the “getServer”.

So, my question is how to program such a “repository” class? In this class I have to be able to check if there is an instance of a given class such that it has a given value of a given field. How can I do it? I need to have a kind of loop over all existing object of a given class?

Another part of my question is why I cannot use associative arrays (associative container, map, mapping, dictionary, finite map)? (I am not sure how do you call it in Java) In more details, I have an “array” which maps names of objects to objects. So, whenever I create a new object, I add a new element to the array: myArray["NameOfServer"] = new Server("NameOfServer").

  • 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-14T00:12:39+00:00Added an answer on May 14, 2026 at 12:12 am

    I would implement it with an associative container myself, however it is better to hide implementation details behind an appropriate interface. That makes it easier to use for clients, and easier for you to change/finetune the implementation over time.

    For example, you may start out with a simple HashMap and find out later that for some reason, a TreeMap would be better. Or you realize that over time, a lot of unused objects accumulate in the map, which are not referenced by anyone else anymore but can’t be garbage collected because the map keeps a reference to them. So you may decide to switch to a WeakHashMap. If your implementation is hidden behind an interface, you can do these changes without affecting clients.

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

Sidebar

Related Questions

I have a single NSDictionary object which contains a large number of custom objects.
I have a large number objects which are tree like structures. I have a
Suppose I have a large number of strings formatted something like: <tag>blah blahXXXXXblah blah</tag>
I have a large number of files in a .tar.gz archive. Checking the file
I have a large number of 2D points and I want to quickly get
I have a large number of files in a ClearCase directory structure, and I
We have a large number of Window Mobile Devices (Symbol MC35 & MC70). I
So I have a large number of very large ASCII files of numerical data
I still have a large number of floppies. On some of them there probably
Question We have a large number of xml configuration files that we want merged

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.