⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 javalang.doc6.html

📁 java语言规范
💻 HTML
📖 第 1 页 / 共 2 页
字号:
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 hexadecimal digits:<p>
<pre><a name="7339"></a><code>0123456789abcdef
</code></pre><a name="7340"></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">(&#167;20.12.36)</a> 
of class <code>String</code> may be called on the result:
<p><pre><a name="7344"></a>Long.toHexString(n).toUpperCase()
</pre><a name="7345"></a>
<p><font size=+1><strong>20.7.15   </strong> <code>public static String <code><b>toOctalString</b></code>(int i)</code></font>
<p>
<a name="7346"></a>
The argument is converted to an unsigned representation in octal radix (base 8); 
this representation is returned as a string.
<p><a name="24668"></a>
The result represents the unsigned magnitude of the argument. This equals the argument plus <img src="javalang.doc.anc32.gif">if the argument is negative; otherwise, it equals the argument.<p>
<a name="7351"></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 octal digits are:<p>
<pre><a name="7352"></a><code>01234567
</code></pre><a name="7353"></a>
These are the characters <code>'\u0030'</code> through <code>'\u0037'</code>.
<p><a name="7354"></a>
<p><font size=+1><strong>20.7.16   </strong> <code>public static String <code><b>toBinaryString</b></code>(int i)</code></font>
<p>
<a name="7355"></a>
The argument is converted to an unsigned representation in binary radix (base 2); 
this representation is returned as a string.
<p><a name="24675"></a>
The result represents the unsigned magnitude of the argument. This equals the argument plus <img src="javalang.doc.anc33.gif">if the argument is negative; otherwise, it equals the argument.<p>
<a name="3839"></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="19810"></a>
<p><font size=+1><strong>20.7.17   </strong> <code>public static int <code><b>parseInt</b></code>(String s)<br>	throws NumberFormatException</code></font>
<p>
<a name="19811"></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 integer value is 
returned, exactly as if the argument and the radix <code>10</code> were given as arguments to 
the <code>parseInt</code> method that takes two arguments <a href="javalang.doc6.html#4930">(&#167;20.7.18)</a>.
<p><a name="4930"></a>
<p><font size=+1><strong>20.7.18   </strong> <code>public static int <code><b>parseInt</b></code>(String s, int radix)<br>	throws NumberFormatException</code></font>
<p>
<a name="4947"></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">(&#167;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 integer value is returned.
<p><a name="5009"></a>
An exception of type <code>NumberFormatException</code> is thrown if any of the following situations occurs:<p>
<ul><a name="24728"></a>
<li>The first argument is <code>null</code> or is a string of length zero.
<a name="24739"></a>
<li>The <code>radix</code> is either smaller than <code>Character.MIN_RADIX</code> <a href="javalang.doc4.html#1300">(&#167;20.5.3)</a> or larger than <code>Character.MAX_RADIX</code> <a href="javalang.doc4.html#1311">(&#167;20.5.4)</a>.
<a name="24730"></a>
<li>Any character of the string is not a digit of the specified <code>radix</code>, except that the first character may <code>be </code>a minus sign <code>'-'</code> (<code>'\u002d'</code>) provided that the string is longer than length 1.
<a name="5049"></a>
<li>The integer value represented by the string is not a value of type <code>int</code>.
</ul><a name="5103"></a>
Examples:<p>
<pre><a name="5118"></a>
parseInt("0", 10) returns 0
<a name="5122"></a>parseInt("473", 10) returns 473
<a name="5126"></a>parseInt("-0", 10) returns 0
<a name="5130"></a>parseInt("-FF", 16) returns -255
<a name="5134"></a>parseInt("1100110", 2) returns 102
<a name="5180"></a>parseInt("2147483647", 10) returns 2147483647
<a name="5184"></a>parseInt("-2147483648", 10) returns -2147483648
<a name="5176"></a>parseInt("2147483648", 10) throws a NumberFormatException
<a name="5205"></a>parseInt("99", 8) throws a NumberFormatException
<a name="5215"></a>parseInt("Kona", 10) throws a NumberFormatException
<a name="5219"></a>parseInt("Kona", 27) returns 411787
</pre><a name="2452"></a>
<p><font size=+1><strong>20.7.19   </strong> <code>public static Integer <code><b>valueOf</b></code>(String s)<br>	throws NumberFormatException</code></font>
<p>
<a name="5053"></a>
The argument is interpreted as representing a signed decimal integer, exactly as if 
the argument were given to the <code>parseInt</code> method that takes one argument 
<a href="javalang.doc6.html#19810">(&#167;20.7.17)</a>. The result is an <code>Integer</code> object that represents the integer value specified
by the string.
<p><a name="5070"></a>
In other words, this method returns an <code>Integer</code> object equal to the value of:<p>
<pre><a name="5071"></a>new Integer(Integer.parseInt(s))
</pre><a name="14370"></a>
<p><font size=+1><strong>20.7.20   </strong> <code>public static Integer <code><b>valueOf</b></code>(String s, int radix)<br>throws NumberFormatException</code></font>
<p>
<a name="5080"></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>parseInt</code> method that takes two arguments <a href="javalang.doc6.html#4930">(&#167;20.7.18)</a>. The result is an <code>Integer</code> 
object that represents the integer value specified by the string.
<p><a name="5084"></a>
In other words, this method returns an <code>Integer</code> object equal to the value of:<p>
<pre><a name="5085"></a>new Integer(Integer.parseInt(s, radix))
</pre><a name="14384"></a>
<p><font size=+1><strong>20.7.21   </strong> <code>public static Integer <code><b>getInteger</b></code>(String nm)</code></font>
<p>
<a name="5322"></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> (&#167;20.18.9)</a>. The string value of this property
is then interpreted as an integer value and an <code>Integer</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="5330"></a>
In other words, this method returns an <code>Integer</code> object equal to the value of:<p>
<pre><a name="5331"></a>getInteger(nm, null)
</pre><a name="14385"></a>
<p><font size=+1><strong>20.7.22   </strong> <code>public static Integer <code><b>getInteger</b></code>(String nm, int val)</code></font>
<p>
<a name="5276"></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> (&#167;20.18.9)</a>. The string value of this property
is then interpreted as an integer value and an <code>Integer</code> object representing this 
value is returned. If the property does not have the correct numeric format, then an 
<code>Integer</code> object that represents the value of the second argument is returned.
<p><a name="5293"></a>
In other words, this method returns an <code>Integer</code> object equal to the value of:<p>
<pre><a name="5294"></a>getInteger(nm, new Integer(val))
</pre><a name="5304"></a>
but in practice it may be implemented in a manner such as:
<p><pre><a name="5308"></a>
Integer result = getInteger(nm, null);
<a name="5305"></a>return (result == null) ? new Integer(val) : result;
</pre><a name="5306"></a>
to avoid the unnecessary allocation of an <code>Integer</code> object when the default value is 
not needed.
<p><a name="14386"></a>
<p><font size=+1><strong>20.7.23   </strong> <code>public static Integer <code><b>getInteger</b></code>(String nm, Integer val)</code></font>
<p>
<a name="5227"></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> (&#167;20.18.9)</a>. The string value of this property
is then interpreted as an integer value and an <code>Integer</code> object representing this 
value is returned.
<p><ul><a name="5237"></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>Integer.valueOf</code> <a href="javalang.doc6.html#14370">(&#167;20.7.20)</a> with radix <code>16</code>.
<a name="5244"></a>
<li>If the property value begins with the ASCII character <code>0</code> followed by another character, it is parsed as an octal integer exactly as for the method <code>Integer.valueOf</code> <a href="javalang.doc6.html#14370">(&#167;20.7.20)</a> with radix <code>8</code>.
<a name="5251"></a>
<li>Otherwise, the property value is parsed as a decimal integer exactly as for the method <code>Integer.valueOf</code> <a href="javalang.doc6.html#14370">(&#167;20.7.20)</a> with radix <code>10</code>.
</ul><a name="46748"></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.doc5.html">Prev</a> | <a href="javalang.doc7.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 &#169 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 + -