Java Byte longValue()方法及示例
Byte类的 longValue() 方法是Java中的一个内置方法,用于将该Byte对象的值作为long值返回。
语法
ByteObject.longValue()
返回值: 它将ByteObject的值作为long返回。
下面是longValue()方法在Java中的实现。
例1 :
// Java code to demonstrate// Byte longValue() method class GFG { public static void main(String[] args) { // byte value byte a = 17; // wrapping the byte value // in the wrapper class Byte Byte b = new Byte(a); // longValue of the Byte 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// Byte longValue() method class GFG { public static void main(String[] args) { String value = "17"; // wrapping the byte value // in the wrapper class Byte Byte b = new Byte(value); // longValue of the Byte Object long output = b.longValue(); // printing the output System.out.println("Long value of " + b + " is : " + output); }}
输出:
Long value of 17 is : 17
