📄 javalang.doc7.html
字号:
</code></pre><a name="7214"></a>
These are the characters <code>'\u0030'</code> through <code>'\u0039'</code> and <code>'\u0061'</code> through
<code>'\u0066'</code>. If uppercase letters are desired, the <code>toUpperCase</code> method <a href="javalang.doc11.html#14011">(§20.12.36)</a>
of class <code>String</code> may be called on the result:
<p><pre><a name="7218"></a>Long.toHexString(n).toUpperCase()
</pre><a name="7251"></a>
<p><font size=+1><strong>20.8.15 </strong> <code>public static String <code><b>toOctalString</b></code>(long i)</code></font>
<p>
<a name="7252"></a>
The argument is converted to an unsigned representation in octal radix (base 8);
this representation is returned as a string.
<p><a name="24807"></a>
The result represents the unsigned magnitude of the argument. This equals the argument plus <img src="javalang.doc.anc34.gif">if the argument is negative; otherwise, it equals the argument.<p>
<a name="7257"></a>
If the unsigned magnitude is zero, it is represented by a single zero character <code>'0'</code> (<code>'\u0030'</code>); otherwise, the first character of the representation of the unsigned magnitude will not be the zero character. The following characters are used as octal digits:<p>
<pre><a name="7258"></a><code>01234567
</code></pre><a name="7259"></a>
These are the characters <code>'\u0030'</code> through <code>'\u0037'</code>.
<p><a name="7299"></a>
<p><font size=+1><strong>20.8.16 </strong> <code>public static String <code><b>toBinaryString</b></code>(long i)</code></font>
<p>
<a name="7300"></a>
The argument is converted to an unsigned representation in binary radix (base 2);
this representation is returned as a string.
<p><a name="24814"></a>
The result represents the unsigned magnitude of the argument. This equals the argument plus <img src="javalang.doc.anc35.gif">if the argument is negative; otherwise, it equals the argument.<p>
<a name="7305"></a>
If the unsigned magnitude is zero, it is represented by a single zero character <code>'0'</code> (<code>'\u0030'</code>); otherwise, the first character of the representation of the unsigned magnitude will not be the zero character. The characters <code>'0'</code> (<code>'\u0030'</code>) and <code>'1'</code> (<code>'\u0031'</code>) are used as binary digits.<p>
<a name="14437"></a>
<p><font size=+1><strong>20.8.17 </strong> <code>public static long <code><b>parseLong</b></code>(String s)<br>throws NumberFormatException</code></font>
<p>
<a name="5339"></a>
The argument is interpreted as representing a signed decimal integer. The components
of the string must all be decimal digits, except that the first character may be
<code>'-'</code> (<code>'\u002d'</code>) to indicate a negative value. The resulting <code>long</code> value is returned,
exactly as if the argument and the radix <code>10</code> were given as arguments to the
<code>parseLong</code> method that takes two arguments <a href="javalang.doc7.html#2483">(§20.8.18)</a>.
<p><a name="24849"></a>
Note that neither <code>L</code> nor <code>l</code> is permitted to appear at the end of the string as a type indicator, as would be permitted in Java source code <a href="3.doc.html#48282">(§3.10.1)</a>.<p>
<a name="2483"></a>
<p><font size=+1><strong>20.8.18 </strong> <code>public static long <code><b>parseLong</b></code>(String s, int radix)<br>throws NumberFormatException</code></font>
<p>
<a name="5349"></a>
The first argument is interpreted as representing a signed integer in the radix specified
by the second argument. The components of the string must all be digits of
the specified radix (as determined by whether <code>Character.digit</code> <a href="javalang.doc4.html#13834">(§20.5.23)</a>
returns a nonnegative value), except that the first character may be <code>'-'</code>
(<code>'\u002d'</code>) to indicate a negative value. The resulting <code>long</code> value is returned.
<p><a name="24839"></a>
Note that neither <code>L</code> nor <code>l</code> is permitted to appear at the end of the string as a type indicator, as would be permitted in Java source code <a href="3.doc.html#48282">(§3.10.1)</a>-except that either <code>L</code> or <code>l</code> may appear as a digit for a radix greater than <code>22</code>.<p>
<a name="5353"></a>
An exception of type <code>NumberFormatException</code> is thrown if any of the following situations occurs:<p>
<ul><a name="5354"></a>
<li>The first argument is <code>null</code> or is a string of length zero.
<a name="24749"></a>
<li>The <code>radix</code> is either smaller than <code>Character.MIN_RADIX</code> <a href="javalang.doc4.html#1300">(§20.5.3)</a> or larger than <code>Character.MAX_RADIX</code> <a href="javalang.doc4.html#1311">(§20.5.4)</a>.
<a name="5355"></a>
<li>The first character of the string is not a digit of the specified <code>radix</code> and is not a minus sign <code>'-'</code> (<code>'\u002d'</code>).
<a name="5356"></a>
<li>The first character of the string is a minus sign and the string is of length 1.
<a name="5357"></a>
<li>Any character of the string after the first is not a digit of the specified <code>radix</code>.
<a name="5358"></a>
<li>The integer value represented by the string cannot be represented as a value of type <code>long</code>.
</ul><a name="5366"></a>
Examples:<p>
<pre><a name="5367"></a>
parseLong("0", 10) returns 0L
<a name="5368"></a>parseLong("473", 10) returns 473L
<a name="5369"></a>parseLong("-0", 10) returns 0L
<a name="5370"></a>parseLong("-FF", 16) returns -255L
<a name="5371"></a>parseLong("1100110", 2) returns 102L
<a name="5375"></a>parseLong("99", 8) throws a NumberFormatException
<a name="5376"></a>parseLong("Hazelnut", 10) throws a NumberFormatException
<a name="5377"></a>parseLong("Hazelnut", 36) returns <code>1356099454469L
</code></pre><a name="14442"></a>
<p><font size=+1><strong>20.8.19 </strong> <code>public static Long <code><b>valueOf</b></code>(String s)<br>throws NumberFormatException</code></font>
<p>
<a name="5447"></a>
The argument is interpreted as representing a signed decimal integer, exactly as if
the argument were given to the <code>parseLong</code> method that takes one argument
<a href="javalang.doc7.html#14437">(§20.8.17)</a>. The result is a <code>Long</code> object that represents the integer value specified
by the string.
<p><a name="5451"></a>
In other words, this method returns a <code>Long</code> object equal to the value of:<p>
<pre><a name="5452"></a>new Long(Long.parseLong(s))
</pre><a name="2489"></a>
<p><font size=+1><strong>20.8.20 </strong> <code>public static Long <code><b>valueOf</b></code>(String s, int radix)<br>throws NumberFormatException</code></font>
<p>
<a name="5466"></a>
The first argument is interpreted as representing a signed integer in the radix specified
by the second argument, exactly as if the arguments were given to the
<code>parseLong</code> method that takes two arguments <a href="javalang.doc7.html#2483">(§20.8.18)</a>. The result is a <code>Long</code>
object that represents the integer value specified by the string.
<p><a name="5470"></a>
In other words, this method returns a <code>Long</code> object equal to the value of:<p>
<pre><a name="5471"></a>new Long(Long.parseLong(s, radix))
</pre><a name="14454"></a>
<p><font size=+1><strong>20.8.21 </strong> <code>public static Long <code><b>getLong</b></code>(String nm)</code></font>
<p>
<a name="5485"></a>
The first argument is treated as the name of a system property to be obtained as if
by the method <code>System.getProperty</code> (§20.18.9)</a>. The string value of this property
is then interpreted as an integer value and a <code>Long</code> object representing this
value is returned. If there is no property of the specified name, or if the property
does not have the correct numeric format, then <code>null</code> is returned.
<p><a name="5493"></a>
In other words, this method returns a <code>Long</code> object equal to the value of:<p>
<pre><a name="5494"></a>getLong(nm, null)
</pre><a name="14455"></a>
<p><font size=+1><strong>20.8.22 </strong> <code>public static Long <code><b>getLong</b></code>(String nm, long val)</code></font>
<p>
<a name="5509"></a>
The first argument is treated as the name of a system property to be obtained as if
by the method <code>System.getProperty</code> (§20.18.9)</a>. The string value of this property
is then interpreted as an integer value and a <code>Long</code> object representing this
value is returned. If there is no property of the specified name, or if the property
does not have the correct numeric format, then a <code>Long</code> object that represents the
value of the second argument is returned.
<p><a name="5517"></a>
In other words, this method returns a <code>Long</code> object equal to the value of:<p>
<pre><a name="5518"></a>getLong(nm, new Long(val))
</pre><a name="5519"></a>
but in practice it may be implemented in a manner such as:
<p><pre><a name="5520"></a>
Long result = getLong(nm, null);
<a name="5521"></a>return (result == null) ? new Long(val) : result;
</pre><a name="5522"></a>
to avoid the unnecessary allocation of a <code>Long</code> object when the default value is not
needed.
<p><a name="14456"></a>
<p><font size=+1><strong>20.8.23 </strong> <code>public static Long <code><b>getLong</b></code>(String nm, Long val)</code></font>
<p>
<a name="5555"></a>
The first argument is treated as the name of a system property to be obtained as if
by the method <code>System.getProperty</code> (§20.18.9)</a>. The string value of this property
is then interpreted as an integer value and a <code>Long</code> object representing this
value is returned.
<p><ul><a name="34299"></a>
<li>If the property value begins with the two ASCII characters <code>0x</code> or the ASCII character <code>#</code>, not followed by a minus sign, then the rest of it is parsed as a hexadecimal integer exactly as for the method <code>Long.valueOf</code> <a href="javalang.doc6.html#14370">(§20.7.20)</a> with radix <code>16</code>.
</ul><ul><a name="24878"></a>
<li>If the property value begins with the character <code>0</code> followed by another character, it is parsed as an octal integer exactly as for the method <code>Long.valueOf</code> <a href="javalang.doc6.html#14370">(§20.7.20)</a> with radix <code>8</code>.
<a name="24882"></a>
<li>Otherwise the property value is parsed as a decimal integer exactly as for the method <code>Long.valueOf</code> <a href="javalang.doc6.html#14370">(§20.7.20)</a> with radix <code>10</code>.
</ul><a name="5571"></a>
Note that, in every case, neither <code>L</code> nor <code>l</code> is permitted to appear at the end of the property value as a type indicator, as would be permitted in Java source code <a href="3.doc.html#48282">(§3.10.1)</a>.<p>
<a name="5595"></a>
The second argument serves as a default value. If there is no property of the specified name, or if the property does not have the correct numeric format, then the second argument is returned.<p>
<hr>
<!-- This inserts footnotes--><p>
<a href="index.html">Contents</a> | <a href="javalang.doc6.html">Prev</a> | <a href="javalang.doc8.html">Next</a> | <a href="j.index.doc1.html">Index</a>
<p>
<font size=-1>Java Language Specification (HTML generated by Suzette Pelouch on February 24, 1998)<br>
<i><a href="jcopyright.doc.html">Copyright © 1996 Sun Microsystems, Inc.</a>
All rights reserved</i>
<br>
Please send any comments or corrections to <a href="mailto:doug.kramer@sun.com">doug.kramer@sun.com</a>
</font>
</body></html>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -