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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T21:39:47+00:00 2026-05-25T21:39:47+00:00

Say you had this DTO class: public class MyObj{ private int id; private String

  • 0

Say you had this DTO class:

public class MyObj{
 private int id;

 private String displayName;
 private String backendData;

 public boolean equals(Object obj){
  return id.equals(obj);
 }

 private int hashCode(){
  return id.hashCode();
 }
}

Lets say a user got to pick several instances of MyObj from a list that only showed the displayName and the id# is associated in the background. To save bandwidth, you don’t send backendData. When they submit their selection back to you, the client just sends you the id#.

Now, you’ve maintained the list of original options server side in a Collection<MyObj>. The naive approach to geting the “full” object back from the collection would be to iterate through the Collection and call “.equals()” on every object. This scales in O(n) though 🙁

It seems like with constant time operations collections like HashSet, I should be able to retrieve an object in constant time, if I know it’s identity. But HashSet only has a “contains()” method and doesn’t return the object it found.

Any advice? As always, thanks a bunch stackOverFlow!

  • 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-25T21:39:47+00:00Added an answer on May 25, 2026 at 9:39 pm

    I assume id is unique across the collection?

    You are almost there use a Map<Integer, MyObj> then map.get(id) is asymptotically constant time.

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

Sidebar

Related Questions

Say if I had a string which had this text/html stored in it: Hello.
I had this doubt for sometime now, some people say that there's no such
I've had this problem a couple of times. Let's say I want to display
Let's say I had: protected void performLogic(List<Object> docs) { ... } In the code
Say I had this code $x = array("a", "b", "c", "d", "e"); Is there
How would I loop through a multidimensional array? Say we had something like this:
How can you check whether a string is convertible to an int? Let's say
So lets say I had this switch: switch(str){ case something: //a defined value //
Can anyone please help me? Say if I had this text or a smaller
I have had this problem for a while, Let say we have a movies

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.