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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T10:42:00+00:00 2026-06-13T10:42:00+00:00

I am working an a Hashing based program . My question is will the

  • 0

I am working an a Hashing based program .
My question is will the HashCode of a String will remain the same for the entire application .

The reason i was asking this because , the KetamaMemcachedSessionLocator inside Mecached Servers works this way
If there are two servers on which Memcache is running , i want to locate a key from a Particular server .

String key = "MyString";
int keyid = key.hashCode();
int v = keyid % 1;  //( I assume that this will contact the First Server to retrieve that value )
int v = keyid % 2;  //( I assume that this will contact the Second Server to retrieve that value )
String value = MemcachedClient.get(key, v);

Followed to implement the above based on this website

http://dev.mysql.com/doc/refman/5.0/en/ha-memcached-using-hashtypes.html

please share your views , incase if you find any issues if the above way it works .

  • 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-13T10:42:00+00:00Added an answer on June 13, 2026 at 10:42 am

    According to hashcode contract it will always the same if string1.eqauls(string2)

    The java.lang.String hash function

    In an attempt to provide a fast implementation, early versions of the Java String class provided a hashCode() implementation that considered at most 16 characters picked from the string. For some common data this worked very poorly, delivering unacceptably clustered results and consequently slow hashtable performance.

    From Java 1.2, java.lang.String class implements its hashCode() using a product sum algorithm over the entire text of the string. Given an instance s of the java.lang.String class, for example, would have a hash code h(s) defined by

     h(s)=\sum_{i=0}^{n-1}s[i] \cdot 31^{n-1-i}

    where terms are summed using Java 32-bit int addition, s[i] denotes the ith character of the string, and n is the length of s.

    As with any general hashing function, collisions are possible. For example, the strings “FB” and “Ea” have the same hash value. The hashCode() implementation of String uses the prime number 31 and the difference between ‘a’ and ‘B’ is just 31, so the calculation is 70 × 31 + 66 = 69 × 31 + 97.

    Check Collections Framework Enhancements in Java SE 7 as you see there are changes in it and who knows will be.

    The alternative hash function is only applied to keys of type String.

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

Sidebar

Related Questions

I am working on a web based application that will need to store usernames
So, I've been working for some time on connecting hashing out a trivial application,
I am working on a Windows phone 7 application. I am using this implementation
I am working on a system that has been hashing user passwords with MD5
Working with H2 I get this error when I try to write a row
Working on game where plates will be falling from top to bottom. Some plates
Can anyone please tell me the working principle or algorithm for the RS string
I have this working in Glassfish, and if I do not hash my passwords
I'm working of my assignment, in C, which to store 500 string into strings
I'm currently working on an application where we receive private health information. One of

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.