目录

static Integer valueOf(String s, int radix)

描述 (Description)

java.lang.Integer.valueOf(String s, int radix)方法返回一个Integer对象,该对象保存在使用第二个参数radix给出的基数进行解析时从指定的String中提取的值。

声明 (Declaration)

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

public static Integer valueOf(String s, int radix) throws NumberFormatException

参数 (Parameters)

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

  • radix - 这是用于解释s的基数。

返回值 (Return Value)

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

异常 (Exception)

NumberFormatException - 如果String不包含可解析的int。

例子 (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 = "50";
      /* returns a Integer instance representing the specified 
         string with radix 10 */
      System.out.println("Value = " + i.valueOf(str, 10));
   }
} 

让我们编译并运行上面的程序,这将产生以下结果 -

Value = 50
↑回到顶部↑
WIKI教程 @2018