short shortValue()
描述 (Description)
java.lang.Byte.shortValue()以short为单位返回此Byte的值。
声明 (Declaration)
以下是java.lang.Byte.shortValue()方法的声明
public short shortValue()
覆盖 (Overrides)
类Number shortValue
参数 (Parameters)
NA
返回值 (Return Value)
转换为short类型后,此方法返回此对象表示的数值。
异常 (Exception)
NA
例子 (Example)
以下示例显示了lang.Byte.shortValue()方法的用法。
package com.iowiki;
import java.lang.*;
public class ByteDemo {
public static void main(String[] args) {
// create 2 Byte objects b1, b2
Byte b1, b2;
// create 2 short primitives s1, s2
short s1, s2;
// assign values to b1, b2
b1 = new Byte("10");
b2 = new Byte("-10");
// assign short values of b1, b2 to s1, s2
s1 = b1.shortValue();
s2 = b2.shortValue();
String str1 = "short value of Byte " + b1 + " is " + s1;
String str2 = "short value of Byte " + b2 + " is " + s2;
// print s1, s2 values
System.out.println( str1 );
System.out.println( str2 );
}
}
让我们编译并运行上面的程序,这将产生以下结果 -
short value of Byte 10 is 10
short value of Byte -10 is -10