当前位置: 首页>>代码示例 >>用法及示例精选 >>正文


Java Short byteValue()用法及代码示例



Short类的java.lang.Short.byteValue()方法是Java中的内置方法,用于将Short对象的值作为字节返回。

用法

ShortObject.byteValue()

返回值:它返回ShortObject的值作为字节。


下面是Java中byteValue()方法的实现:

示例1:

// Java code to demonstrate 
// Short byteValue() method 
  
class GFG { 
    public static void main(String[] args) 
    { 
  
        // Short value 
        Short a = 17; 
  
        // wrapping the Short value 
        // in the wrapper class Short 
        Short b = new Short(a); 
  
        // byteValue of the Short Object 
        byte output = b.byteValue(); 
  
        // printing the output 
        System.out.println("Byte value of "
                           + b + " is : " + output); 
    } 
}
输出:
Byte value of 17 is : 17

示例2:

// Java code to demonstrate 
// Short byteValue() method 
  
class GFG { 
    public static void main(String[] args) 
    { 
  
        String value = "17"; 
  
        // wrapping the Short value 
        // in the wrapper class Short 
        Short b = new Short(value); 
  
        // byteValue of the Short Object 
        byte output = b.byteValue(); 
  
        // printing the output 
        System.out.println("Byte value of "
                           + b + " is : " + output); 
    } 
}
输出:
Byte value of 17 is : 17


相关用法


注:本文由纯净天空筛选整理自Sruti Rai大神的英文原创作品 Short byteValue() method in Java with Example。非经特殊声明,原始代码版权归原作者所有,本译文未经允许或授权,请勿转载或复制。