目录

static Short valueOf(String s)

描述 (Description)

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

声明 (Declaration)

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

public static Short valueOf(String s) throws NumberFormatException

参数 (Parameters)

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

返回值 (Return Value)

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

异常 (Exception)

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

例子 (Example)

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

package com.iowiki;
import java.lang.*;
public class ShortDemo {
   public static void main(String[] args) {
      short shortNum = 100;
      String str = "600";
      // returns Short object representing given short value
      Short ShortValue = Short.valueOf(shortNum);
      // displays the short object value
      System.out.println("Short object representing the specified short value =
         " + ShortValue);
      // returns a Short object holding the value given by the specified String
      ShortValue = Short.valueOf(str); 
      // displays the short object value
      System.out.println("Short object holding the value given by the specified
         String = " + ShortValue);
   }
}

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

Short object representing the specified short value = 100
Short object holding the value given by the specified String = 600
↑回到顶部↑
WIKI教程 @2018