Byte类的byteValue方法是Java中的一种内置方法,用于将Byte对象的值作为字节返回。
用法
ByteObject.byteValue()
返回值:它返回ByteObject的值作为字节。
下面是Java中byteValue()方法的实现:
示例1:
// Java code to demonstrate
// Byte byteValue() 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);
// byteValue of the Byte Object
byte output = b.byteValue();
// printing the output
System.out.println("Byte value of "
+ a + " is : " + output);
}
}
输出:
Byte value of 17 is : 17
示例2:
// Java code to demonstrate
// Byte byteValue() 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);
// byteValue of the Byte Object
byte output = b.byteValue();
// printing the output
System.out.println("Byte value of "
+ b + " is : " + output);
}
}
输出:
Byte value of 17 is : 17