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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T01:52:18+00:00 2026-05-16T01:52:18+00:00

I would like to implement a fast search on an ArrayList of objects. These

  • 0

I would like to implement a fast search on an ArrayList of objects. These objects consist of an int oldId, int newId and int inList, among with other things.

Now, I tried implementing a binary search using the Collections.binarySearch on my list, but the problem is I need to search using the oldId and inList, to get the newId from the corresponding object. Example: I have oldId = 9 and inList = 1, and try to get the newId that has been assigned somewhere else. Essentially mapped the oldId-newId’s and grouped them. There may be duplicate oldId’s but they must be in different lists, and have unique newIds.

Do you think it would be better to use a hashmap for these map objects? Or else, is there a solution (maybe a comparator for the objects) to get the newId’s from the oldId and inList info. I am also looking for a fast search algorithm.

Thanks a lot for helps, I appreciate ideas.

Here is a comparator I have written for the binary search, however I couldn’t figure out how to add the inList info here.

public class CompareTermId implements Comparator <MObj> {

public CompareTermId(){}

public int compare(MObj a, MObj b){

    if(a.oldTermId < b.oldTermId) return 1;
    else if(a.oldTermId > b.oldTermId) return -1;
    else return 0;
}

}

  • 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-16T01:52:19+00:00Added an answer on May 16, 2026 at 1:52 am

    As you have invited I am going to recommend HashMap 🙂

    The reason is because HashMap provides effectively constant time lookups for a single key.

    If you construct a hash map as follows:

    Map<Id, Map<InList, Id>> oldIdToNewIdMap = new HashMap<>();
    

    And then populate it:

    Map<InList, Id> inListMap = new HashMap<>();
    inListMap.put(oldId, newId);
    oldIdToNewIdMap.put(inList, inListMap);
    

    Then you can lookup as follows:

    Id newId = oldIdToNewIdMap.get(inList).get(oldId);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I would like to implement a fast group by like feature in Java. I
I would like to implement a search function in my android app. I sow
I would like to implement a distinct thread for each route in apache camel.I
I would like to implement a very simple way to store a variable containing
I would like to implement a function with R that removes repeated characters in
I would like to implement a simple queueing service specific to a project. Where
I would like to implement a switch button, android.widget.Switch (available from API v.14). <Switch
I would like to implement a simple AR desktop application. This application should first
I would like to implement something similar to 37Signals's Yellow Fade effect. I am
We would like to implement a web form that automatically saves content at regular

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.