目录

static short parseShort(String s)

描述 (Description)

java.lang.Short.parseShort(String s)方法将字符串参数解析为带符号的十进制short。

声明 (Declaration)

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

public static short parseShort(String s) throws NumberFormatException

参数 (Parameters)

s - 这是一个包含要解析的短表示的String。

返回值 (Return Value)

此方法返回由十进制参数表示的short值。

异常 (Exception)

NumberFormatException - 如果字符串不包含可解析的short。

例子 (Example)

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

package com.iowiki;
import java.lang.*;
public class ShortDemo {
   public static void main(String[] args) {
      String str = "250";
      // returns signed decimal short value of string
      short shortValue = Short.parseShort(str); 
      // prints signed decimalshort value
      System.out.println("Signed decimal short value for given String is =
         " + shortValue);  
   }
}   

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

Signed decimal short value for String is = 250
↑回到顶部↑
WIKI教程 @2018