integer.html
来自「j2se5-api-zh,java文档的中文版本」· HTML 代码 · 共 1,380 行 · 第 1/5 页
HTML
1,380 行
<TH ALIGN="left" COLSPAN="1"><FONT SIZE="+2"><B>构造方法详细信息</B></FONT></TH></TR></TABLE><A NAME="Integer(int)"><!-- --></A><H3>Integer</H3><PRE>public <B>Integer</B>(int value)</PRE><DL><DD>构造一个新分配的 <code>Integer</code> 对象,它表示指定的 <code>int</code> 值。<P><DL><DT><B>参数:</B><DD><CODE>value</CODE> - <code>Integer</code> 对象表示的值。</DL></DL><HR><A NAME="Integer(java.lang.String)"><!-- --></A><H3>Integer</H3><PRE>public <B>Integer</B>(<A HREF="String.html" title="java.lang 中的类">String</A> s) throws <A HREF="NumberFormatException.html" title="java.lang 中的类">NumberFormatException</A></PRE><DL><DD>构造一个新分配的 <code>Integer</code> 对象,它表示 <code>String</code> 参数所指示的 <code>int</code> 值。正好可以使用对基数为 10 的值使用的 <code>parseInt</code> 方法将该字符串转换成 <code>int</code> 值。<P><DL><DT><B>参数:</B><DD><CODE>s</CODE> - 要转换为 <code>Integer</code> 的 <code>String</code>。<DT><B>抛出:</B><DD><CODE><A HREF="NumberFormatException.html" title="java.lang 中的类">NumberFormatException</A></CODE> - 如果 <code>String</code> 不包含可分析的整数。<DT><B>另请参见:</B><DD><A HREF="Integer.html#parseInt(java.lang.String, int)"><CODE>parseInt(java.lang.String, int)</CODE></A></DL></DL><!-- ============ METHOD DETAIL ========== --><A NAME="method_detail"><!-- --></A><TABLE BORDER="1" WIDTH="100%" CELLPADDING="3" CELLSPACING="0" SUMMARY=""><TR BGCOLOR="#CCCCFF" CLASS="TableHeadingColor"><TH ALIGN="left" COLSPAN="1"><FONT SIZE="+2"><B>方法详细信息</B></FONT></TH></TR></TABLE><A NAME="toString(int, int)"><!-- --></A><H3>toString</H3><PRE>public static <A HREF="String.html" title="java.lang 中的类">String</A> <B>toString</B>(int i, int radix)</PRE><DL><DD>用第二个参数指定的基数返回第一个参数的字符串表示形式。 <p>如果基数小于 <code>Character.MIN_RADIX</code> 或者大于 <code>Character.MAX_RADIX</code>,则改用基数 <code>10</code>。 <p>如果第一个参数为负,则结果中的第一个元素为 ASCII 的减号 <code>'-'</code> (<code>'\u002D'</code>)。如果第一个参数为非负,则没有符号字符出现在结果中。 <p>结果中的剩余字符表示第一个参数的大小。如果大小为零,则用一个零字符 <code>'0'</code> (<code>'\u0030'</code>) 表示;否则,大小的表示形式中的第一个字符将不是零字符。用以下 ASCII 字符作为数字: <blockquote><pre> 0123456789abcdefghijklmnopqrstuvwxyz </pre></blockquote>其范围是从 <code>'\u0030'</code> 到 <code>'\u0039'</code> 和从 <code>'\u0061'</code> 到 <code>'\u007A'</code>。如果 <code>radix</code> 为 <var>N</var>, 则按照所示顺序,使用这些字符中的第一个 <var>N</var> 将作为基数-<var>N</var> 数字。因此,十六进制(基数为 16)的数字是 <code>0123456789abcdef</code>。如果希望得到大写字母,则可以在结果上调用 <A HREF="String.html#toUpperCase()"><CODE>String.toUpperCase()</CODE></A> 方法: <blockquote><pre> Integer.toString(n, 16).toUpperCase() </pre></blockquote><P><DD><DL></DL></DD><DD><DL><DT><B>参数:</B><DD><CODE>i</CODE> - 要转换成字符串的整数。<DD><CODE>radix</CODE> - 用于字符串表示形式的基数。<DT><B>返回:</B><DD>使用指定基数的参数的字符串表示形式。<DT><B>另请参见:</B><DD><A HREF="Character.html#MAX_RADIX"><CODE>Character.MAX_RADIX</CODE></A>, <A HREF="Character.html#MIN_RADIX"><CODE>Character.MIN_RADIX</CODE></A></DL></DD></DL><HR><A NAME="toHexString(int)"><!-- --></A><H3>toHexString</H3><PRE>public static <A HREF="String.html" title="java.lang 中的类">String</A> <B>toHexString</B>(int i)</PRE><DL><DD>以十六进制的无符号整数形式返回一个整数参数的字符串表示形式。 <p>如果参数为负,那么无符号整数值为参数加上 2<sup>32</sup>;否则等于该参数。将该值转换为十六进制(基数 16)的无前导 <code>0</code> 的 ASCII 数字字符串。如果无符号数的大小值为零,则用一个零字符 <code>'0'</code> (<code>’\u0030’</code>) 表示它;否则,无符号数大小的表示形式中的第一个字符将不是零字符。用以下字符作为十六进制数字: <blockquote><pre> 0123456789abcdef </pre></blockquote>这些字符的范围是从 <code>'\u0030'</code> 到 <code>'\u0039'</code> 和从 <code>'\u0061'</code> 到 <code>'\u0066'</code>。如果希望得到大写字母,可以在结果上调用 <A HREF="String.html#toUpperCase()"><CODE>String.toUpperCase()</CODE></A> 方法: <blockquote><pre> Integer.toHexString(n).toUpperCase() </pre></blockquote><P><DD><DL></DL></DD><DD><DL><DT><B>参数:</B><DD><CODE>i</CODE> - 要转换成字符串的整数。<DT><B>返回:</B><DD>用十六进制(基数 16)参数表示的无符号整数值的字符串表示形式。<DT><B>从以下版本开始:</B></DT> <DD>JDK1.0.2</DD></DL></DD></DL><HR><A NAME="toOctalString(int)"><!-- --></A><H3>toOctalString</H3><PRE>public static <A HREF="String.html" title="java.lang 中的类">String</A> <B>toOctalString</B>(int i)</PRE><DL><DD>以八进制(基数 8)无符号整数形式返回一个整数参数的字符串表示形式。<p>如果参数为负,该无符号整数值为参数加上 2<sup>32</sup>;否则等于该参数。该值被转换成八进制(基数 8)ASCII 数字的字符串,且没有附加前导 <code>0</code>。<p>如果无符号数大小为零,则用一个零字符 <code>'0'</code> (<code>'\u0030'</code>) 表示它;否则,无符号数大小的表示形式中的第一个字符将不是零字符。用以下字符作为八进制数字:<blockquote><pre>01234567</pre></blockquote>它们是从 <code>'\u0030'</code> 到 <code>'\u0037'</code> 的字符。<P><DD><DL></DL></DD><DD><DL><DT><B>参数:</B><DD><CODE>i</CODE> - 要转换成字符串的整数。<DT><B>返回:</B><DD>用八进制参数(基数 8)表示的无符号整数值的字符串表示形式。<DT><B>从以下版本开始:</B></DT> <DD>JDK1.0.2</DD></DL></DD></DL><HR><A NAME="toBinaryString(int)"><!-- --></A><H3>toBinaryString</H3><PRE>public static <A HREF="String.html" title="java.lang 中的类">String</A> <B>toBinaryString</B>(int i)</PRE><DL><DD>以二进制(基数 2)无符号整数形式返回一个整数参数的字符串表示形式。 <p>如果参数为负,该无符号整数值为参数加上 2<sup>32</sup>;否则等于该参数。将该值转换为二进制(基数 2)形式的无前导 <code>0</code> 的 ASCII 数字字符串。如果无符号数的大小为零,则用一个零字符 <code>'0'</code> (<code>’\u0030’</code>) 表示它;否则,无符号数大小的表示形式中的第一个字符将不是零字符。字符 <code>'0'</code> (<code>'\u0030'</code>) 和 <code>'1'</code> (<code>'\u0031'</code>) 被用作二进制数字。<P><DD><DL></DL></DD><DD><DL><DT><B>参数:</B><DD><CODE>i</CODE> - 要转换为字符串的整数。<DT><B>返回:</B><DD>用二进制(基数 2)参数表示的无符号整数值的字符串表示形式。<DT><B>从以下版本开始:</B></DT> <DD>JDK1.0.2</DD></DL></DD></DL><HR><A NAME="toString(int)"><!-- --></A><H3>toString</H3><PRE>public static <A HREF="String.html" title="java.lang 中的类">String</A> <B>toString</B>(int i)</PRE><DL><DD>返回一个表示指定整数的 <code>String</code> 对象。将该参数转换为有符号的十进制表示形式,以字符串形式返回它,就好像将参数和基数 10 作为参数赋予 <A HREF="Integer.html#toString(int, int)"><CODE>toString(int, int)</CODE></A> 方法。<P><DD><DL></DL></DD><DD><DL><DT><B>参数:</B><DD><CODE>i</CODE> - 要转换的整数。<DT><B>返回:</B><DD>十进制(基数 10)参数的字符串表示形式。</DL></DD></DL><HR><A NAME="parseInt(java.lang.String, int)"><!-- --></A><H3>parseInt</H3><PRE>public static int <B>parseInt</B>(<A HREF="String.html" title="java.lang 中的类">String</A> s, int radix) throws <A HREF="NumberFormatException.html" title="java.lang 中的类">NumberFormatException</A></PRE><DL><DD>使用第二个参数指定的基数,将字符串参数解析为有符号的整数。除了第一个字符可以是用来表示负值的 ASCII 减号 <code>'-'</code> (<code>'\u002D’</code>)外,字符串中的字符必须都是指定基数的数字(通过 <A HREF="Character.html#digit(char, int)"><CODE>Character.digit(char, int)</CODE></A> 是否返回一个负值确定)。返回得到的整数值。 <p>如果发生以下任意一种情况,则抛出一个 <code>NumberFormatException</code> 类型的异常: <ul><li>第一个参数为 <code>null</code> 或一个长度为零的字符串。<li>基数小于 <A HREF="Character.html#MIN_RADIX"><CODE>Character.MIN_RADIX</CODE></A> 或者大于 <A HREF="Character.html#MAX_RADIX"><CODE>Character.MAX_RADIX</CODE></A>。 <li>假如字符串的长度超过 1,那么除了第一个字符可以是减号 <code>'-'</code> (<code>'u002D’</code>) 外,字符串中的任何字符都不是指定基数的数字。<li>字符串表示的值不是 <code>int</code> 类型的值。 </ul><p>示例:<blockquote><pre>parseInt("0", 10) 返回 0parseInt("473", 10) 返回 473parseInt("-0", 10) 返回 0parseInt("-FF", 16) 返回 -255parseInt("1100110", 2) 返回 102parseInt("2147483647", 10) 返回 2147483647parseInt("-2147483648", 10) 返回 -2147483648parseInt("2147483648", 10) 抛出 NumberFormatExceptionparseInt("99", 8) 抛出 NumberFormatExceptionparseInt("Kona", 10) 抛出 NumberFormatExceptionparseInt("Kona", 27) 返回 411787</pre></blockquote><P><DD><DL></DL></DD><DD><DL><DT><B>参数:</B><DD><CODE>s</CODE> - 包含要分析的整数表示形式的 <code>String</code><DD><CODE>radix</CODE> - 分析 <code>s</code> 时使用的基数。<DT><B>返回:</B><DD>使用指定基数的字符串参数表示的整数。<DT><B>抛出:</B><DD><CODE><A HREF="NumberFormatException.html" title="java.lang 中的类">NumberFormatException</A></CODE> - 如果 <code>String</code> 不包含可分析的 <code>int</code>。</DL></DD></DL><HR><A NAME="parseInt(java.lang.String)"><!-- --></A><H3>parseInt</H3><PRE>public static int <B>parseInt</B>(<A HREF="String.html" title="java.lang 中的类">String</A> s) throws <A HREF="NumberFormatException.html" title="java.lang 中的类">NumberFormatException</A></PRE><DL><DD>将字符串参数作为有符号的十进制整数进行分析。除了第一个字符可以是用来表示负值的 ASCII 减号 <code>'-'</code> (<code>'\u002D'</code>) 外,字符串中的字符都必须是十进制数字。返回得到的整数值,就好像将该参数和基数 10 作为参数赋予 <A HREF="Integer.html#parseInt(java.lang.String, int)"><CODE>parseInt(java.lang.String, int)</CODE></A> 方法一样。<P><DD><DL></DL></DD><DD><DL><DT><B>参数:</B><DD><CODE>s</CODE> - 包含要分析的 <code>int</code> 表示形式的 <code>String</code>。<DT><B>返回:</B><DD>用十进制参数表示的整数值。<DT><B>抛出:</B><DD><CODE><A HREF="NumberFormatException.html" title="java.lang 中的类">NumberFormatException</A></CODE> - 如果字符串不包含可分析的整数。</DL></DD></DL><HR><A NAME="valueOf(java.lang.String, int)"><!-- --></A><H3>valueOf</H3><PRE>public static <A HREF="Integer.html" title="java.lang 中的类">Integer</A> <B>valueOf</B>(<A HREF="String.html" title="java.lang 中的类">String</A> s, int radix) throws <A HREF="NumberFormatException.html" title="java.lang 中的类">NumberFormatException</A></PRE><DL><DD>返回一个 <code>Integer</code> 对象,该对象中保存了用第二个参数提供的基数进行分析时从指定的 <code>String</code> 中提取的值。将第一个参数解释为用第二个参数指定的基数表示的有符号整数,就好像将这些参数赋予 <A HREF="Integer.html#parseInt(java.lang.String, int)"><CODE>parseInt(java.lang.String, int)</CODE></A> 方法一样。结果是一个表示字符串指定的整数值的 <code>Integer</code> 对象。<p>换句话说,该方法返回一个等于以下值的 <code>Integer</code> 对象:<blockquote><code>new Integer(Integer.parseInt(s, radix))</code></blockquote><P><DD><DL></DL></DD><DD><DL><DT><B>参数:</B><DD><CODE>s</CODE> - 要解析的字符串。<DD><CODE>radix</CODE> - 解释 <code>s</code> 时使用的基数。<DT><B>返回:</B><DD>保存通过使用指定基数的字符串参数表示的值的 <code>Integer</code> 对象。<DT><B>抛出:</B><DD><CODE><A HREF="NumberFormatException.html" title="java.lang 中的类">NumberFormatException</A></CODE> - 如果 <code>String</code> 不包含可分析的 <code>int</code>。</DL></DD></DL><HR><A NAME="valueOf(java.lang.String)"><!-- --></A><H3>valueOf</H3><PRE>public static <A HREF="Integer.html" title="java.lang 中的类">Integer</A> <B>valueOf</B>(<A HREF="String.html" title="java.lang 中的类">String</A> s) throws <A HREF="NumberFormatException.html" title="java.lang 中的类">NumberFormatException</A></PRE><DL><DD>返回保存指定的 <code>String</code> 的值的 <code>Integer</code> 对象。将该参数解释为表示一个有符号的十进制整数, 就好像将该参数赋予 <A HREF="Integer.html#parseInt(java.lang.String)"><CODE>parseInt(java.lang.String)</CODE></A> 方法一样。结果是一个表示字符串指定的整数值的 <code>Integer</code> 对象。<p>换句话说,该方法返回一个等于以下值的 <code>Integer</code> 对象:<blockquote><code>new Integer(Integer.parseInt(s))</code></blockquote><P><DD><DL></DL></DD><DD><DL><DT><B>参数:</B><DD><CODE>s</CODE> - 要解析的字符串。<DT><B>返回:</B><DD>保存字符串参数表示的值的 <code>Integer</code> 对象。<DT><B>抛出:</B><DD><CODE><A HREF="NumberFormatException.html" title="java.lang 中的类">NumberFormatException</A></CODE> - 如果字符串不能分析为一个整数。</DL></DD></DL>
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?