jdk/src/share/classes/java/lang/Long.java
changeset 11676 7e75ec031b97
parent 11672 a5fa8c844b54
child 12858 97e3f3f77254
equal deleted inserted replaced
11675:7559f1e43e1e 11676:7e75ec031b97
    79      * or larger than {@code Character.MAX_RADIX}, then the radix
    79      * or larger than {@code Character.MAX_RADIX}, then the radix
    80      * {@code 10} is used instead.
    80      * {@code 10} is used instead.
    81      *
    81      *
    82      * <p>If the first argument is negative, the first element of the
    82      * <p>If the first argument is negative, the first element of the
    83      * result is the ASCII minus sign {@code '-'}
    83      * result is the ASCII minus sign {@code '-'}
    84      * (<code>'&#92;u002d'</code>). If the first argument is not
    84      * ({@code '\u005Cu002d'}). If the first argument is not
    85      * negative, no sign character appears in the result.
    85      * negative, no sign character appears in the result.
    86      *
    86      *
    87      * <p>The remaining characters of the result represent the magnitude
    87      * <p>The remaining characters of the result represent the magnitude
    88      * of the first argument. If the magnitude is zero, it is
    88      * of the first argument. If the magnitude is zero, it is
    89      * represented by a single zero character {@code '0'}
    89      * represented by a single zero character {@code '0'}
    90      * (<code>'&#92;u0030'</code>); otherwise, the first character of
    90      * ({@code '\u005Cu0030'}); otherwise, the first character of
    91      * the representation of the magnitude will not be the zero
    91      * the representation of the magnitude will not be the zero
    92      * character.  The following ASCII characters are used as digits:
    92      * character.  The following ASCII characters are used as digits:
    93      *
    93      *
    94      * <blockquote>
    94      * <blockquote>
    95      *   {@code 0123456789abcdefghijklmnopqrstuvwxyz}
    95      *   {@code 0123456789abcdefghijklmnopqrstuvwxyz}
    96      * </blockquote>
    96      * </blockquote>
    97      *
    97      *
    98      * These are <code>'&#92;u0030'</code> through
    98      * These are {@code '\u005Cu0030'} through
    99      * <code>'&#92;u0039'</code> and <code>'&#92;u0061'</code> through
    99      * {@code '\u005Cu0039'} and {@code '\u005Cu0061'} through
   100      * <code>'&#92;u007a'</code>. If {@code radix} is
   100      * {@code '\u005Cu007a'}. If {@code radix} is
   101      * <var>N</var>, then the first <var>N</var> of these characters
   101      * <var>N</var>, then the first <var>N</var> of these characters
   102      * are used as radix-<var>N</var> digits in the order shown. Thus,
   102      * are used as radix-<var>N</var> digits in the order shown. Thus,
   103      * the digits for hexadecimal (radix 16) are
   103      * the digits for hexadecimal (radix 16) are
   104      * {@code 0123456789abcdef}. If uppercase letters are
   104      * {@code 0123456789abcdef}. If uppercase letters are
   105      * desired, the {@link java.lang.String#toUpperCase()} method may
   105      * desired, the {@link java.lang.String#toUpperCase()} method may
   152      *
   152      *
   153      * <p>Note that since the first argument is treated as an unsigned
   153      * <p>Note that since the first argument is treated as an unsigned
   154      * value, no leading sign character is printed.
   154      * value, no leading sign character is printed.
   155      *
   155      *
   156      * <p>If the magnitude is zero, it is represented by a single zero
   156      * <p>If the magnitude is zero, it is represented by a single zero
   157      * character {@code '0'} (<code>'&#92;u0030'</code>); otherwise,
   157      * character {@code '0'} ({@code '\u005Cu0030'}); otherwise,
   158      * the first character of the representation of the magnitude will
   158      * the first character of the representation of the magnitude will
   159      * not be the zero character.
   159      * not be the zero character.
   160      *
   160      *
   161      * <p>The behavior of radixes and the characters used as digits
   161      * <p>The behavior of radixes and the characters used as digits
   162      * are the same as {@link #toString(long, int) toString}.
   162      * are the same as {@link #toString(long, int) toString}.
   237      * string {@code s} by calling {@link
   237      * string {@code s} by calling {@link
   238      * Long#parseUnsignedLong(String, int) Long.parseUnsignedLong(s,
   238      * Long#parseUnsignedLong(String, int) Long.parseUnsignedLong(s,
   239      * 16)}.
   239      * 16)}.
   240      *
   240      *
   241      * <p>If the unsigned magnitude is zero, it is represented by a
   241      * <p>If the unsigned magnitude is zero, it is represented by a
   242      * single zero character {@code '0'} (<code>'&#92;u0030'</code>);
   242      * single zero character {@code '0'} ({@code '\u005Cu0030'});
   243      * otherwise, the first character of the representation of the
   243      * otherwise, the first character of the representation of the
   244      * unsigned magnitude will not be the zero character. The
   244      * unsigned magnitude will not be the zero character. The
   245      * following characters are used as hexadecimal digits:
   245      * following characters are used as hexadecimal digits:
   246      *
   246      *
   247      * <blockquote>
   247      * <blockquote>
   248      *  {@code 0123456789abcdef}
   248      *  {@code 0123456789abcdef}
   249      * </blockquote>
   249      * </blockquote>
   250      *
   250      *
   251      * These are the characters <code>'&#92;u0030'</code> through
   251      * These are the characters {@code '\u005Cu0030'} through
   252      * <code>'&#92;u0039'</code> and  <code>'&#92;u0061'</code> through
   252      * {@code '\u005Cu0039'} and  {@code '\u005Cu0061'} through
   253      * <code>'&#92;u0066'</code>.  If uppercase letters are desired,
   253      * {@code '\u005Cu0066'}.  If uppercase letters are desired,
   254      * the {@link java.lang.String#toUpperCase()} method may be called
   254      * the {@link java.lang.String#toUpperCase()} method may be called
   255      * on the result:
   255      * on the result:
   256      *
   256      *
   257      * <blockquote>
   257      * <blockquote>
   258      *  {@code Long.toHexString(n).toUpperCase()}
   258      *  {@code Long.toHexString(n).toUpperCase()}
   284      * string {@code s} by calling {@link
   284      * string {@code s} by calling {@link
   285      * Long#parseUnsignedLong(String, int) Long.parseUnsignedLong(s,
   285      * Long#parseUnsignedLong(String, int) Long.parseUnsignedLong(s,
   286      * 8)}.
   286      * 8)}.
   287      *
   287      *
   288      * <p>If the unsigned magnitude is zero, it is represented by a
   288      * <p>If the unsigned magnitude is zero, it is represented by a
   289      * single zero character {@code '0'} (<code>'&#92;u0030'</code>);
   289      * single zero character {@code '0'} ({@code '\u005Cu0030'});
   290      * otherwise, the first character of the representation of the
   290      * otherwise, the first character of the representation of the
   291      * unsigned magnitude will not be the zero character. The
   291      * unsigned magnitude will not be the zero character. The
   292      * following characters are used as octal digits:
   292      * following characters are used as octal digits:
   293      *
   293      *
   294      * <blockquote>
   294      * <blockquote>
   295      *  {@code 01234567}
   295      *  {@code 01234567}
   296      * </blockquote>
   296      * </blockquote>
   297      *
   297      *
   298      * These are the characters <code>'&#92;u0030'</code> through
   298      * These are the characters {@code '\u005Cu0030'} through
   299      * <code>'&#92;u0037'</code>.
   299      * {@code '\u005Cu0037'}.
   300      *
   300      *
   301      * @param   i   a {@code long} to be converted to a string.
   301      * @param   i   a {@code long} to be converted to a string.
   302      * @return  the string representation of the unsigned {@code long}
   302      * @return  the string representation of the unsigned {@code long}
   303      *          value represented by the argument in octal (base&nbsp;8).
   303      *          value represented by the argument in octal (base&nbsp;8).
   304      * @see #parseUnsignedLong(String, int)
   304      * @see #parseUnsignedLong(String, int)
   323      * string {@code s} by calling {@link
   323      * string {@code s} by calling {@link
   324      * Long#parseUnsignedLong(String, int) Long.parseUnsignedLong(s,
   324      * Long#parseUnsignedLong(String, int) Long.parseUnsignedLong(s,
   325      * 2)}.
   325      * 2)}.
   326      *
   326      *
   327      * <p>If the unsigned magnitude is zero, it is represented by a
   327      * <p>If the unsigned magnitude is zero, it is represented by a
   328      * single zero character {@code '0'} (<code>'&#92;u0030'</code>);
   328      * single zero character {@code '0'} ({@code '\u005Cu0030'});
   329      * otherwise, the first character of the representation of the
   329      * otherwise, the first character of the representation of the
   330      * unsigned magnitude will not be the zero character. The
   330      * unsigned magnitude will not be the zero character. The
   331      * characters {@code '0'} (<code>'&#92;u0030'</code>) and {@code
   331      * characters {@code '0'} ({@code '\u005Cu0030'}) and {@code
   332      * '1'} (<code>'&#92;u0031'</code>) are used as binary digits.
   332      * '1'} ({@code '\u005Cu0031'}) are used as binary digits.
   333      *
   333      *
   334      * @param   i   a {@code long} to be converted to a string.
   334      * @param   i   a {@code long} to be converted to a string.
   335      * @return  the string representation of the unsigned {@code long}
   335      * @return  the string representation of the unsigned {@code long}
   336      *          value represented by the argument in binary (base&nbsp;2).
   336      *          value represented by the argument in binary (base&nbsp;2).
   337      * @see #parseUnsignedLong(String, int)
   337      * @see #parseUnsignedLong(String, int)
   465      * Parses the string argument as a signed {@code long} in the
   465      * Parses the string argument as a signed {@code long} in the
   466      * radix specified by the second argument. The characters in the
   466      * radix specified by the second argument. The characters in the
   467      * string must all be digits of the specified radix (as determined
   467      * string must all be digits of the specified radix (as determined
   468      * by whether {@link java.lang.Character#digit(char, int)} returns
   468      * by whether {@link java.lang.Character#digit(char, int)} returns
   469      * a nonnegative value), except that the first character may be an
   469      * a nonnegative value), except that the first character may be an
   470      * ASCII minus sign {@code '-'} (<code>'&#92;u002D'</code>) to
   470      * ASCII minus sign {@code '-'} ({@code '\u005Cu002D'}) to
   471      * indicate a negative value or an ASCII plus sign {@code '+'}
   471      * indicate a negative value or an ASCII plus sign {@code '+'}
   472      * (<code>'&#92;u002B'</code>) to indicate a positive value. The
   472      * ({@code '\u005Cu002B'}) to indicate a positive value. The
   473      * resulting {@code long} value is returned.
   473      * resulting {@code long} value is returned.
   474      *
   474      *
   475      * <p>Note that neither the character {@code L}
   475      * <p>Note that neither the character {@code L}
   476      * (<code>'&#92;u004C'</code>) nor {@code l}
   476      * ({@code '\u005Cu004C'}) nor {@code l}
   477      * (<code>'&#92;u006C'</code>) is permitted to appear at the end
   477      * ({@code '\u005Cu006C'}) is permitted to appear at the end
   478      * of the string as a type indicator, as would be permitted in
   478      * of the string as a type indicator, as would be permitted in
   479      * Java programming language source code - except that either
   479      * Java programming language source code - except that either
   480      * {@code L} or {@code l} may appear as a digit for a
   480      * {@code L} or {@code l} may appear as a digit for a
   481      * radix greater than 22.
   481      * radix greater than 22.
   482      *
   482      *
   491      * java.lang.Character#MIN_RADIX} or larger than {@link
   491      * java.lang.Character#MIN_RADIX} or larger than {@link
   492      * java.lang.Character#MAX_RADIX}.
   492      * java.lang.Character#MAX_RADIX}.
   493      *
   493      *
   494      * <li>Any character of the string is not a digit of the specified
   494      * <li>Any character of the string is not a digit of the specified
   495      * radix, except that the first character may be a minus sign
   495      * radix, except that the first character may be a minus sign
   496      * {@code '-'} (<code>'&#92;u002d'</code>) or plus sign {@code
   496      * {@code '-'} ({@code '\u005Cu002d'}) or plus sign {@code
   497      * '+'} (<code>'&#92;u002B'</code>) provided that the string is
   497      * '+'} ({@code '\u005Cu002B'}) provided that the string is
   498      * longer than length 1.
   498      * longer than length 1.
   499      *
   499      *
   500      * <li>The value represented by the string is not a value of type
   500      * <li>The value represented by the string is not a value of type
   501      *      {@code long}.
   501      *      {@code long}.
   502      * </ul>
   502      * </ul>
   582 
   582 
   583     /**
   583     /**
   584      * Parses the string argument as a signed decimal {@code long}.
   584      * Parses the string argument as a signed decimal {@code long}.
   585      * The characters in the string must all be decimal digits, except
   585      * The characters in the string must all be decimal digits, except
   586      * that the first character may be an ASCII minus sign {@code '-'}
   586      * that the first character may be an ASCII minus sign {@code '-'}
   587      * (<code>&#92;u002D'</code>) to indicate a negative value or an
   587      * ({@code \u005Cu002D'}) to indicate a negative value or an
   588      * ASCII plus sign {@code '+'} (<code>'&#92;u002B'</code>) to
   588      * ASCII plus sign {@code '+'} ({@code '\u005Cu002B'}) to
   589      * indicate a positive value. The resulting {@code long} value is
   589      * indicate a positive value. The resulting {@code long} value is
   590      * returned, exactly as if the argument and the radix {@code 10}
   590      * returned, exactly as if the argument and the radix {@code 10}
   591      * were given as arguments to the {@link
   591      * were given as arguments to the {@link
   592      * #parseLong(java.lang.String, int)} method.
   592      * #parseLong(java.lang.String, int)} method.
   593      *
   593      *
   594      * <p>Note that neither the character {@code L}
   594      * <p>Note that neither the character {@code L}
   595      * (<code>'&#92;u004C'</code>) nor {@code l}
   595      * ({@code '\u005Cu004C'}) nor {@code l}
   596      * (<code>'&#92;u006C'</code>) is permitted to appear at the end
   596      * ({@code '\u005Cu006C'}) is permitted to appear at the end
   597      * of the string as a type indicator, as would be permitted in
   597      * of the string as a type indicator, as would be permitted in
   598      * Java programming language source code.
   598      * Java programming language source code.
   599      *
   599      *
   600      * @param      s   a {@code String} containing the {@code long}
   600      * @param      s   a {@code String} containing the {@code long}
   601      *             representation to be parsed
   601      *             representation to be parsed
   616      *
   616      *
   617      * The characters in the string must all be digits of the
   617      * The characters in the string must all be digits of the
   618      * specified radix (as determined by whether {@link
   618      * specified radix (as determined by whether {@link
   619      * java.lang.Character#digit(char, int)} returns a nonnegative
   619      * java.lang.Character#digit(char, int)} returns a nonnegative
   620      * value), except that the first character may be an ASCII plus
   620      * value), except that the first character may be an ASCII plus
   621      * sign {@code '+'} (<code>'&#92;u002B'</code>). The resulting
   621      * sign {@code '+'} ({@code '\u005Cu002B'}). The resulting
   622      * integer value is returned.
   622      * integer value is returned.
   623      *
   623      *
   624      * <p>An exception of type {@code NumberFormatException} is
   624      * <p>An exception of type {@code NumberFormatException} is
   625      * thrown if any of the following situations occurs:
   625      * thrown if any of the following situations occurs:
   626      * <ul>
   626      * <ul>
   631      * {@link java.lang.Character#MIN_RADIX} or
   631      * {@link java.lang.Character#MIN_RADIX} or
   632      * larger than {@link java.lang.Character#MAX_RADIX}.
   632      * larger than {@link java.lang.Character#MAX_RADIX}.
   633      *
   633      *
   634      * <li>Any character of the string is not a digit of the specified
   634      * <li>Any character of the string is not a digit of the specified
   635      * radix, except that the first character may be a plus sign
   635      * radix, except that the first character may be a plus sign
   636      * {@code '+'} (<code>'&#92;u002B'</code>) provided that the
   636      * {@code '+'} ({@code '\u005Cu002B'}) provided that the
   637      * string is longer than length 1.
   637      * string is longer than length 1.
   638      *
   638      *
   639      * <li>The value represented by the string is larger than the
   639      * <li>The value represented by the string is larger than the
   640      * largest unsigned {@code long}, 2<sup>64</sup>-1.
   640      * largest unsigned {@code long}, 2<sup>64</sup>-1.
   641      *
   641      *
   705 
   705 
   706     /**
   706     /**
   707      * Parses the string argument as an unsigned decimal {@code long}. The
   707      * Parses the string argument as an unsigned decimal {@code long}. The
   708      * characters in the string must all be decimal digits, except
   708      * characters in the string must all be decimal digits, except
   709      * that the first character may be an an ASCII plus sign {@code
   709      * that the first character may be an an ASCII plus sign {@code
   710      * '+'} (<code>'&#92;u002B'</code>). The resulting integer value
   710      * '+'} ({@code '\u005Cu002B'}). The resulting integer value
   711      * is returned, exactly as if the argument and the radix 10 were
   711      * is returned, exactly as if the argument and the radix 10 were
   712      * given as arguments to the {@link
   712      * given as arguments to the {@link
   713      * #parseUnsignedLong(java.lang.String, int)} method.
   713      * #parseUnsignedLong(java.lang.String, int)} method.
   714      *
   714      *
   715      * @param s   a {@code String} containing the unsigned {@code long}
   715      * @param s   a {@code String} containing the unsigned {@code long}
  1146      * integer exactly as by the method
  1146      * integer exactly as by the method
  1147      * {@link #valueOf(java.lang.String, int)} with radix 10.
  1147      * {@link #valueOf(java.lang.String, int)} with radix 10.
  1148      * </ul>
  1148      * </ul>
  1149      *
  1149      *
  1150      * <p>Note that, in every case, neither {@code L}
  1150      * <p>Note that, in every case, neither {@code L}
  1151      * (<code>'&#92;u004C'</code>) nor {@code l}
  1151      * ({@code '\u005Cu004C'}) nor {@code l}
  1152      * (<code>'&#92;u006C'</code>) is permitted to appear at the end
  1152      * ({@code '\u005Cu006C'}) is permitted to appear at the end
  1153      * of the property value as a type indicator, as would be
  1153      * of the property value as a type indicator, as would be
  1154      * permitted in Java programming language source code.
  1154      * permitted in Java programming language source code.
  1155      *
  1155      *
  1156      * <p>The second argument is the default value. The default value is
  1156      * <p>The second argument is the default value. The default value is
  1157      * returned if there is no property of the specified name, if the
  1157      * returned if there is no property of the specified name, if the