<html><head><meta name="color-scheme" content="light dark"></head><body><pre style="word-wrap: break-word; white-space: pre-wrap;">// String.hashCode

    /** The value is used for character storage. */
    private final char value[];

    /** The offset is the first index of the storage that is used. */
    private final int offset;

    /** The count is the number of characters in the String. */
    private final int count;

    /** Cache the hash code for the string */
    private int hash; // Default to 0

    /**
     * Returns a hash code for this string. The hash code for a
     * &lt;code&gt;String&lt;/code&gt; object is computed as
     * &lt;blockquote&gt;&lt;pre&gt;
     * s[0]*31^(n-1) + s[1]*31^(n-2) + ... + s[n-1]
     * &lt;/pre&gt;&lt;/blockquote&gt;
     * using &lt;code&gt;int&lt;/code&gt; arithmetic, where &lt;code&gt;s[i]&lt;/code&gt; is the
     * &lt;i&gt;i&lt;/i&gt;th character of the string, &lt;code&gt;n&lt;/code&gt; is the length of
     * the string, and &lt;code&gt;^&lt;/code&gt; indicates exponentiation.
     * (The hash value of the empty string is zero.)
     *
     * @return a hash code value for this object.
     */
    public int hashCode()
        {
        int h = hash;
        if ( h == 0 )
            {
            int off = offset;
            char val[] = value;
            int len = count;

            for ( int i = 0; i &lt; len; i++ )
                {
                h = 31 * h + val[ off++ ];
                }
            hash = h;
            }
        return h;
        }
</pre></body></html>