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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T19:42:37+00:00 2026-06-05T19:42:37+00:00

I am using a hashmap to store objects with a key that evolves over

  • 0

I am using a hashmap to store objects with a key that evolves over time.

HashMap<String,Stuff> hm = new HashMap<String,Stuff>()
Stuff stuff = new Stuff();
hm.put( "OrignalKey", stuff);

I didn’t find anything better than removing “OrignalKey” and put() a new entry with the same object.

hm.remove("OriginalKey");
hm.put("NewKey", stuff);

remove() seems to be taking a significant cpu toll hence my questions:

  1. What is the actual the memory cost to leave duplicate entries (there is no overlapping risk)?
  2. Am I just missing some neat swapKey() method?
  • 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-05T19:42:39+00:00Added an answer on June 5, 2026 at 7:42 pm

    What is the actual the memory cost to leave duplicate entries (there is no overlapping risk)?

    Well, you’ve got an extra entry, and the key itself can’t be garbage collected. If the key is “large”, that could be a problem. It also means that you’ll never be able to get an accurate count, you’ll never be able to sensibly iterate over all the values, etc. It seems like a bad idea to me.

    Am I just missing some neat swapKey() method?

    There’s no such thing – and it feels like a fairly rare requirement to me. Any such method would pretty much have to do what you’re doing anyway – it has to find the old key, remove it from the data structure, and insert an entry for the new key. I can’t easily imagine any optimizations possible just by knowing about both operations at once.

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

Sidebar

Related Questions

When using a HashMap, will the hashmap store the entire objectA as a key
I'm building a thesaurus using a HashMap to store the synonyms. I'm trying to
I'm using a HashMap . When I iterate over the map, the data is
I'm building a thesaurus using a HashMap <String,ArrayList<String>> to hold words and their synonyms
I have a HashMap that I'm using in Processing and I'd like to increment
I'm using the following code to read a map of type HashMap<String, String >
I was thinking of using a Double as the key to a HashMap but
I have for instance this Map: Map<String, Integer> map = new HashMap<String,Integer>(); than I
I have a HashMap. The key will be a string and value can be
What are the prons and cons between using static Hashmap store object and apache

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.