目录

static Integer valueOf(String s)

描述 (Description)

java.lang.Integer.valueOf(String s)方法返回一个Integer对象,该对象包含指定String s值。

声明 (Declaration)

以下是java.lang.Integer.valueOf()方法的声明

public static Integer valueOf(String s) throws NumberFormatException

参数 (Parameters)

s - 这是要解析的字符串。

返回值 (Return Value)

此方法返回一个Integer对象,该对象包含字符串参数表示的值。

异常 (Exception)

NumberFormatException - 如果字符串无法解析为整数。

例子 (Example)

以下示例显示了java.lang.Integer.valueOf()方法的用法。

package com.iowiki;
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
↑回到顶部↑
WIKI教程 @2018