java.lang.Short.parseShort(String s)%uA0方法解析字符串参数为有符号的十进制short值。
声明
以下是java.lang.Short.parseShort()方法的声明
public static short parseShort(String s) throws NumberFormatException
参数
-
s%uA0-- 这是要分析包含short表示的字符串。
返回值
此方法返回由十进制参数表示的short值。
异常
-
NumberFormatException%uA0-- 如果该字符串不包含一个可分析的short。
例子
下面的例子显示java.lang.Short.parseShort()方法的使用。
package com.yiibai 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