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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T17:54:39+00:00 2026-05-26T17:54:39+00:00

I believe that if I declare a HashMap and repeatedly feed it instances of

  • 0

I believe that if I declare a HashMap and repeatedly feed it instances of Map.Entry eventually a hashcode will collide with another hashcode even if the two keys (which happen to be Strings for my needs) are different.

At that point HashMap and other classes that use hashing will produce a different hash code which serves as the real key for internal use. (Edit: this turned out to be not true. Please see the selected answer.)

Is there a way to get that internal key? The reason I want it is because a 32 bit key is more efficient memory and speed-wise than the real world key which would be a (possibly) longish string.

I can make a hash code registry for my Strings but why bother if Java already can do this.

  • 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-26T17:54:40+00:00Added an answer on May 26, 2026 at 5:54 pm

    No. You can’t get a unique 32 bit number for every possible object in your system.

    The simplest proof for this is that on a 64bit JVM with sufficient amounts of memory you can easily have more than 2^32 objects: thus you’d need more than 2^32 different hash values. But since you only have 32 bits to store those hash values, you can’t get more than 2^32 different hash values. This is called the Pidgeonhole principle.

    Also: HashMap doesn’t produce a “unique hash code”: it simply stores all elements with the same hash code in the same bucket (in a linked list) and checks every one of them using equals() if it has to retrieve one of those.

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

Sidebar

Related Questions

I believe that the rallytagpicker is definitely a useful component. However, I do not
I believe that UIView objects can delegate control to views in iOS programming. However,
I believe that I did everything necessary to change my app for ipad (was
I believe that in C99, modification of string literals is undefined behaviour. I don't
I used to believe that any variable that is shared between two threads, can
I am beginning to believe that unit testing high level, well-written code, which requires
I was lead to believe that MVC apps were BIN-deployable, so could be deployed
I can't believe that the following statement seems to be still true So, I
I don't believe that I am using any 3.0 specific APIs, but somehow whenever
THIRD EDIT: I now believe that this problem is due to a SOAP version

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.