Hash values in Java

Source: Internet
Author: User

The following are all pasted from the source code of the String class.

1 Private intHash//Default to 02  Public inthashcode () {3         inth =Hash;4         if(h = = 0 && value.length > 0) {5             CharVal[] =value;6              for(inti = 0; i < value.length; i++) {7H = * H +Val[i];8             }9hash =h;Ten         } One         returnh; A}

The following method is used to calculate the hash value of the string "Lee"

The ASCII code for ' L ' is 101 , andthe ASCII code for ' E ' is

For Loop 3 times

    1. h=31*0+76=76
    2. h=31*76+101=2457
    3. h=31*2457+101=76268

So the hash code for the string "Lee" is 76268 .

Hash value in Java

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.