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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T14:41:24+00:00 2026-05-11T14:41:24+00:00

The hashCode value of a Java String is computed as ( String.hashCode() ): s[0]*31^(n-1)

  • 0

The hashCode value of a Java String is computed as (String.hashCode()):

s[0]*31^(n-1) + s[1]*31^(n-2) + ... + s[n-1] 

Are there any circumstances (say JVM version, vendor, etc.) under which the following expression will evaluate to false?

boolean expression = 'This is a Java string'.hashCode() == 586653468 

Update #1: If you claim that the answer is ‘yes, there are such circumstances’ – then please give a concrete example of when ‘This is a Java string’.hashCode() != 586653468. Try to be as specific/concrete as possible.

Update #2: We all know that relying on the implementation details of hashCode() is bad in general. However, I’m talking specifically about String.hashCode() – so please keep the answer focused to String.hashCode(). Object.hashCode() is totally irrelevant in the context of this question.

  • 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. 2026-05-11T14:41:25+00:00Added an answer on May 11, 2026 at 2:41 pm

    I can see that documentation as far back as Java 1.2.

    While it’s true that in general you shouldn’t rely on a hash code implementation remaining the same, it’s now documented behaviour for java.lang.String, so changing it would count as breaking existing contracts.

    Wherever possible, you shouldn’t rely on hash codes staying the same across versions etc – but in my mind java.lang.String is a special case simply because the algorithm has been specified… so long as you’re willing to abandon compatibility with releases before the algorithm was specified, of course.

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

Sidebar

Ask A Question

Stats

  • Questions 119k
  • Answers 119k
  • 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 Get "Cocoa Programming for Mac OS X by Aaron Hillegass"… May 11, 2026 at 11:46 pm
  • Editorial Team
    Editorial Team added an answer I think AppData is what you want. You can use… May 11, 2026 at 11:46 pm
  • Editorial Team
    Editorial Team added an answer After adding the field again, you need to call .datepicker… May 11, 2026 at 11:46 pm

Related Questions

The JDK documentation for java.lang.String.hashCode() famously says: The hash code for a String object
I've recently started using code coverage tools (particularily Emma and EclEmma), and I really
In Java, I have a subclass Vertex of the Java3D class Point3f . Now
I'd like to compare some large objects representing trees and cache something to avoid

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.