當前位置: 首頁>>代碼示例 >>用法及示例精選 >>正文


Java Short longValue()用法及代碼示例



Short類的java.lang.Short.longValue()方法是Java中的內置方法,用於將Short對象的值返回為long。

用法

ShortObject.longValue()

返回值:它返回ShortObject的值,隻要long。


下麵是Java中longValue()方法的實現:

示例1:

// Java code to demonstrate 
// Short longValue() 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); 
  
        // longValue of the Short Object 
        long output = b.longValue(); 
  
        // printing the output 
        System.out.println("Long value of "
                           + b + " is : " + output); 
    } 
}
輸出:
Long value of 17 is : 17

示例2:

// Java code to demonstrate 
// Short longValue() 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); 
  
        // longValue of the Short Object 
        long output = b.longValue(); 
  
        // printing the output 
        System.out.println("Long value of "
                           + b + " is : " + output); 
    } 
}
輸出:
Long value of 17 is : 17


相關用法


注:本文由純淨天空篩選整理自Sruti Rai大神的英文原創作品 Short longValue() method in Java with Example。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。