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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T13:39:59+00:00 2026-05-28T13:39:59+00:00

A hastable uses some hash function on an object to store. This hash function

  • 0

A hastable uses some hash function on an object to store.

This hash function essentially calculates the position of the object in the table.

If we use a HashTable or HashMap and the size can not fit more elements then these collections are resized to accomodate more elements.
This means that each stored element must be rehashed to calculate the new position in the new bigger table.

My question is the following(that the above are correct):
I read that String calculates its hashcode by using the characters that it stores and additionally that the hashvalue is stored internally (cached) for best performance since it does not have to be recalculated.

This is the part I don’t get.If the hashcode is based on the characters the String stores then how is the position in the hashtable calculated?

Is there some extra logic using the hashcode of String? So the String‘s hashcode is not actually the hashvalue?

  • 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-28T13:40:00+00:00Added an answer on May 28, 2026 at 1:40 pm

    The hashcode is not changed. Only the position in the internal table is. Open HashMap and see:

    static int indexFor(int h, int length) {
        return h & (length-1);
    }
    

    The index within the table (array, actually) is determined based on the hash and the size of the array.

    So, when “rehashing” happens, it uses the same hashcode, but a different length, which means the element is put in a different bucket.

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

Sidebar

Related Questions

I need debug some old code that uses a Hashtable to store response from
If I'm using a Hashtable , I can write code like this: object item
I am having some problem with java hashtable. Following is my hastable key and
How to store object or hashtable in cookies? I am trying to store multiple
I'm maintaining a Java web application that uses a java.util.Hashtable to cache values. This
The hashtable and map is hashtable is implemented as a hash function but map
This is not a question about the differences between Hashtable and HashMap . I
I have a hashtable . values() method returns values in some order different from
I have some code which populates a hashtable with a question as the key
Following java method returns keys of hashtable as Enumeration. Hashtable<String, Object> props = new

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.