Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > de.comp.lang.java > #13280
| From | Bonita Montero <Bonita.Montero@gmail.com> |
|---|---|
| Newsgroups | de.comp.lang.java |
| Subject | Re: Java String.hashCode-Algorithmus |
| Date | 2019-08-26 11:01 +0200 |
| Organization | albasani.net |
| Message-ID | <qk074p$5j4$2@news.albasani.net> (permalink) |
| References | <qk042t$cj4$1@news.albasani.net> <qk062f$otl$1@news-cypress.fernuni-hagen.de> |
>> Ist der Algorithmus von hashCode für String irgenddwo dokumentiert?
> Was spricht denn gegen einen Blick in den Quellcode?
>
> /**
> * Returns a hash code for this string. The hash code for a
> * {@code String} object is computed as
> * <blockquote><pre>
> * s[0]*31^(n-1) + s[1]*31^(n-2) + ... + s[n-1]
> * </pre></blockquote>
> * using {@code int} arithmetic, where {@code s[i]} is the
> * <i>i</i>th character of the string, {@code n} is the length of
> * the string, and {@code ^} 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 && value.length > 0) {
> char val[] = value;
>
> for (int i = 0; i < value.length; i++) {
> h = 31 * h + val[i];
> }
> hash = h;
> }
> return h;
> }
Das ist aber was anderes als was die Doku sagt:
https://docs.oracle.com/javase/9/docs/api/java/lang/String.html#hashCode--
Back to de.comp.lang.java | Previous | Next — Previous in thread | Next in thread | Find similar
Java String.hashCode-Algorithmus Bonita Montero <Bonita.Montero@gmail.com> - 2019-08-26 10:09 +0200
Re: Java String.hashCode-Algorithmus Bonita Montero <Bonita.Montero@gmail.com> - 2019-08-26 10:11 +0200
Re: Java String.hashCode-Algorithmus Michael Paap <feunews@mpaap.de> - 2019-08-26 10:42 +0200
Re: Java String.hashCode-Algorithmus Bonita Montero <Bonita.Montero@gmail.com> - 2019-08-26 11:01 +0200
Re: Java String.hashCode-Algorithmus Michael Paap <feunews@mpaap.de> - 2019-08-26 11:05 +0200
Re: Java String.hashCode-Algorithmus Michael Paap <feunews@mpaap.de> - 2019-08-26 11:09 +0200
Re: Java String.hashCode-Algorithmus Bonita Montero <Bonita.Montero@gmail.com> - 2019-08-26 11:33 +0200
Re: Java String.hashCode-Algorithmus Patrick Roemer <sangamon@netcologne.de> - 2019-08-26 11:53 +0200
Re: Java String.hashCode-Algorithmus Michael Paap <feunews@mpaap.de> - 2019-08-26 11:46 +0200
Re: Java String.hashCode-Algorithmus Bonita Montero <Bonita.Montero@gmail.com> - 2019-08-26 13:05 +0200
Re: Java String.hashCode-Algorithmus Joerg Meier <joergmmeier@arcor.de> - 2019-08-26 13:27 +0200
Re: Java String.hashCode-Algorithmus Michael Paap <feunews@mpaap.de> - 2019-08-26 14:17 +0200
Re: Java String.hashCode-Algorithmus Joerg Meier <joergmmeier@arcor.de> - 2019-08-26 17:23 +0200
Re: Java String.hashCode-Algorithmus Michael Paap <feunews@mpaap.de> - 2019-08-26 14:14 +0200
Re: Java String.hashCode-Algorithmus Claus Reibenstein <4spamersonly@kabelmail.de> - 2019-08-26 13:10 +0200
Re: Java String.hashCode-Algorithmus Wanja Gayk <brixomatic@yahoo.com> - 2019-09-20 16:57 +0200
csiph-web