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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T21:11:21+00:00 2026-05-31T21:11:21+00:00

Lets say I have a list of 1,000,000 users where their unique identifier is

  • 0

Lets say I have a list of 1,000,000 users where their unique identifier is their username string. So to compare two User objects I just override the compareTo() method an compare the username members.

Given a username string I wish to find the User object from a list. What, in an average case, would be the fastest way to do this.

I’m guessing a HashMap, mapping usernames to User objects, but I wondered if there was something else that I didn’t know about which would be better.

  • 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-31T21:11:22+00:00Added an answer on May 31, 2026 at 9:11 pm

    If you don’t need to store them in a database (which is the usual scenario), a HashMap<String, User> would work fine – it has O(1) complexity for lookup.

    As noted, the usual scenario is to have them in the database. But in order to get faster results, caching is utilized. You can use EhCache – it is similar to ConcurrentHashMap, but it has time-to-live for elements and the option to be distributed across multiple machines.

    You should not dump your whole database in memory, because it will be hard to synchronize. You will face issues with invalidating the entries in the map and keeping them up-to-date. Caching frameworks make all this easier. Also note that the database has its own optimizations, and it is not unlikely that your users will be kept in memory there for faster access.

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

Sidebar

Related Questions

Lets say I have this code: public void MyMethod(string Data, List<string> InputData) { //I
Lets say I have List<string> = new List<string>() {20,26,32} I want to create a
lets say I have a list like so: ['one','two','three','four','five','six','seven','eight','nine'] and I want to experiment
Lets say. If i have 1,000,000 users registered on my system and I have
lets say i have a list of urls such as http://stackexchange.com https://stackoverflow.com/users/login http://careers.stackoverflow.com http://chat.stackoverflow.com
Lets say you have a list of items: <ul id=ImportantNumbers> <li id=one></li> <li id=two></li>
Lets say I have a list: L = [15,16,57,59,14] The list contains mesurements, that
Lets say i have the following unordered list <ul> <li><a>Hank</a></li> <li><a>Alice</a></li> <li><a>Tom</a></li> <li><a>Ashlee</a></li> </ul>
Lets say a have the following Model public class FirstModel { public List<SecondModel> SecondModels
Lets say I have a database of widgets. I am showing a list of

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.