static Integer decode(String nm)
描述 (Description)
java.lang.Integer.decode()方法将String解码为Integer。 它接受十进制,十六进制和八进制数。
声明 (Declaration)
以下是java.lang.Integer.decode()方法的声明
public static Integer decode(String nm) throws NumberFormatException
参数 (Parameters)
nm - 这是要解码的字符串。
返回值 (Return Value)
此方法返回一个Integer对象,该对象包含由nm表示的int值。
异常 (Exception)
NumberFormatException - 如果String不包含可解析的整数。
例子 (Example)
以下示例显示了java.lang.Integer.decode()方法的用法。
package com.iowiki;
import java.lang.*;
public class IntegerDemo {
public static void main(String[] args) {
Integer i = new Integer(10);
String str = "50";
/* returns an Integer object holding the int value represented
by string str */
System.out.println("Number = " + i.decode(str));
}
}
让我们编译并运行上面的程序,这将产生以下结果 -
Number = 50