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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T05:35:08+00:00 2026-06-16T05:35:08+00:00

I have list (array list)that can contain many instances (between 500-3000 instances ). during

  • 0

I have list (array list)that can contain many instances (between 500-3000 instances ).
during the program some function need to access to this list (many times)and search for specific instance or more ,to get the instance\s they need loop on the list and provide parentName and name (which is string) and are not uniqe key .

my question is since the list need to be accessed many time there is a way to define/design it better that the access to the list can be more efficient?

Please keep in mind that the functions that need to get instance/s from the list
cannot provide full key the can provide only name and parentName which can have more that one instance.

List<Obj>   myList = new ArrayList<Obj>();

class obj
{
parentName
Name
type 
curr
....
  • 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-16T05:35:10+00:00Added an answer on June 16, 2026 at 5:35 am

    Use a Map<MyEntry, List<Obj>> where MyEntry is a class enclosing parent name and name as such:

    public final class MyEntry
    {
        private final String parentName;
        private final String name;
        private final int hashCode;
    
        public MyEntry(final String parentName, final String name)
        {
            this.parentName = parentName;
            this.name = name;
            hashCode = 31 * parentName.hashCode() + name.hashCode();
        }
    
        // Override .equals() and .hashCode()
        @Override
        public int hashCode()
        {
            return hashCode;
        }
    
        @Override
        public boolean equals(final Object o)
        {
            if (this == o)
                return true;
            if (o == null)
                return false;
            if (getClass() != o.getClass())
                return false;
            final MyEntry other = (MyEntry) o;
            return parentName.equals(other.parentName)
                && name.equals(other.name);
        }
    
        // Have a nice string representation
        @Override
        public String toString()
        {
            return "parent name: " + parentName + ", name: " + name;
        }
    }
    

    You can, for instance, have a method in your Obj which returns the matching MyEntry object. Also, if you use Guava, have a look at MultiMap.

    You will notice that the hash code is precomputed: this can be done since the MyEntry class is immutable. This allows for very fast usage as keys for a Map.

    (edit: added .toString())

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

Sidebar

Related Questions

I have an array list that could contain component or composite and each component
I have an array List<SomeObject> which contain ascending order of dates (and some more
I am just trying to display a list from an array that I have
In .NET, both array and list have Enumerable as ancestor, so a method that
I have many large (>35,000,000) lists of integers that will contain duplicates. I need
i have a doubt about if i can pass an array that content the
Some beta-users of my upcoming app are reporting that the list of contacts contain
I have a list of Object arrays (List) That I am going to pass
I have been trying to serialize a list that contains arrays and lists. I
I have a List with array of object values. I have to display value

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.