1456
1457 /**
1458 * Returns a hash code for this string. The hash code for a
1459 * {@code String} object is computed as
1460 * <blockquote><pre>
1461 * s[0]*31^(n-1) + s[1]*31^(n-2) + ... + s[n-1]
1462 * </pre></blockquote>
1463 * using {@code int} arithmetic, where {@code s[i]} is the
1464 * <i>i</i>th character of the string, {@code n} is the length of
1465 * the string, and {@code ^} indicates exponentiation.
1466 * (The hash value of the empty string is zero.)
1467 *
1468 * @return a hash code value for this object.
1469 */
1470 public int hashCode() {
1471 int h = hash;
1472 if (h == 0) {
1473 for (char v : value) {
1474 h = 31 * h + v;
1475 }
1476 hash = h;
1477 }
1478 return h;
1479 }
1480
1481 /**
1482 * Returns the index within this string of the first occurrence of
1483 * the specified character. If a character with value
1484 * {@code ch} occurs in the character sequence represented by
1485 * this {@code String} object, then the index (in Unicode
1486 * code units) of the first such occurrence is returned. For
1487 * values of {@code ch} in the range from 0 to 0xFFFF
1488 * (inclusive), this is the smallest value <i>k</i> such that:
1489 * <blockquote><pre>
1490 * this.charAt(<i>k</i>) == ch
1491 * </pre></blockquote>
1492 * is true. For other values of {@code ch}, it is the
1493 * smallest value <i>k</i> such that:
1494 * <blockquote><pre>
1495 * this.codePointAt(<i>k</i>) == ch
1496 * </pre></blockquote>
|
1456
1457 /**
1458 * Returns a hash code for this string. The hash code for a
1459 * {@code String} object is computed as
1460 * <blockquote><pre>
1461 * s[0]*31^(n-1) + s[1]*31^(n-2) + ... + s[n-1]
1462 * </pre></blockquote>
1463 * using {@code int} arithmetic, where {@code s[i]} is the
1464 * <i>i</i>th character of the string, {@code n} is the length of
1465 * the string, and {@code ^} indicates exponentiation.
1466 * (The hash value of the empty string is zero.)
1467 *
1468 * @return a hash code value for this object.
1469 */
1470 public int hashCode() {
1471 int h = hash;
1472 if (h == 0) {
1473 for (char v : value) {
1474 h = 31 * h + v;
1475 }
1476 if (h != 0) {
1477 hash = h;
1478 }
1479 }
1480 return h;
1481 }
1482
1483 /**
1484 * Returns the index within this string of the first occurrence of
1485 * the specified character. If a character with value
1486 * {@code ch} occurs in the character sequence represented by
1487 * this {@code String} object, then the index (in Unicode
1488 * code units) of the first such occurrence is returned. For
1489 * values of {@code ch} in the range from 0 to 0xFFFF
1490 * (inclusive), this is the smallest value <i>k</i> such that:
1491 * <blockquote><pre>
1492 * this.charAt(<i>k</i>) == ch
1493 * </pre></blockquote>
1494 * is true. For other values of {@code ch}, it is the
1495 * smallest value <i>k</i> such that:
1496 * <blockquote><pre>
1497 * this.codePointAt(<i>k</i>) == ch
1498 * </pre></blockquote>
|