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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T09:04:18+00:00 2026-05-13T09:04:18+00:00

I want to store some objects and then be able to retrieve them later

  • 0

I want to store some objects and then be able to retrieve them later as efficiently as possible. I will also remove some of them under certain conditions. It seems a hash map would be the right choice.

But, from what I’ve seen, hash maps always associate a value with another? For example, “john” and “555-5555”, his phone number.

Now, my situation. Suppose I have a bunch of people, and each person is connected to other people. So, I need each person to store its contacts.

What I’m doing is have each person have a hashmap, and then I’d add to the hash otherPerson, otherPerson. Basically, the key is the value. Am I doing it wrong?

EDIT I don’t think the HashSet would solve my problem because I have to retrieve the value to update it and there is no get method. Remove returns a boolean, so I can’t even remove it to put it back again, which would probably be a bad idea anyway.

  • 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-13T09:04:19+00:00Added an answer on May 13, 2026 at 9:04 am

    I don’t think the HashSet would solve my problem because I have to retrieve the value to update it and there is no get method.

    This is a puzzling statement. Why would you want to retrieve a value using a get method to update it? Surely, if you know which object you need to retrieve from the set/map, you don’t need to retrieve it.

    For example:

    HashSet<Person> relations = ...
    Person p = ...
    if (relations.remove(p)) {
        // we removed an object such that p.equals(obj) is true.
    }
    

    Now if you are worried that the object that was removed was equal to, but not identical to p, it seems to me that something is wrong with your design. Either:

    • you should not be creating multiple Person instances that are equal, or
    • you should not be caring that Person instances are not identical, or
    • you should not have overridden equals(Object).

    In short, the problem is that you are not managing object identity properly.

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

Sidebar

Ask A Question

Stats

  • Questions 249k
  • Answers 249k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer Let's look at one of open-source features. If you want… May 13, 2026 at 9:04 am
  • Editorial Team
    Editorial Team added an answer Use jQuery: $(window).bind("load resize", function(){ $('.right-block').width($('.main-block').width() - (25)); }); May 13, 2026 at 9:04 am
  • Editorial Team
    Editorial Team added an answer In an unsafe context, this will work in C#: int… May 13, 2026 at 9:04 am

Related Questions

Suppose I have some objects, and I want the user to be able to
this is probably something I should know, but I'm puzzled by this. I'm trying
I have recently found myself becoming more negative about EF and cannot help wondering
I'm writing some console applications to move some data between SQLite databases. The classes
I have run into trouble trying to implement functionality for serializing some classes in

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.