java.lang.Integer.valueOf(String s)%uA0方法返回一个Integer对象持有的指定字符串s的值。
声明
以下是java.lang.Integer.valueOf()方法的声明
public static Integer valueOf(String s) throws NumberFormatException
参数
-
s%uA0-- 这是要被解析的字符串。
返回值
此方法返回一个Integer对象由字符串参数表示的值。
异常
-
NumberFormatException%uA0-- 如果字符串不能解析为一个整数。
例子
下面的例子显示java.lang.Integer.valueOf()方法的使用。
package com.yiibai import java.lang.* public class IntegerDemo { public static void main(String[] args) { Integer i = new Integer(30) String str = "5" // returns a Integer instance representing the specified string System.out.println("Value = " + i.valueOf(str)) } }
让我们来编译和运行上面的程序,这将产生以下结果:
Value = 5