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