Java.lang.Byte.shortValue() 方法
描述
java.lang.Byte.shortValue() 将此 Byte 的值作为 short 返回。
声明
以下是 java.lang.Byte.shortValue() 方法的声明。
public short shortValue()
覆盖
Number 类中的 shortValue
参数
NA
返回值
该方法在转换为short类型后返回该对象表示的数值。
异常
NA
示例
下面的例子展示了 lang.Byte.shortValue() 方法的使用。
package com.tutorialspoint;
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

